Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python pandas to excel error

I have a dataframe that I want to export to Excel. I'm new to python and pandas so I need some help on this simple task.

df2.to_excel('C:\BT\stack_test3.xlsx')

Error message:

IOError: [Errno 13] Permission denied: 'C:\BT\stack_test3.xlsx'

like image 802
jonas Avatar asked Dec 15 '22 06:12

jonas


1 Answers

You path is incorrect, because you have not escaped the slashes it thinks you are trying to write to the root of c: drive use the following:

df2.to_excel(r'C:\BT\stack_test3.xlsx')

The r makes the path a raw string and means you do not need to escape the slashes

Edit

It seems that there is some error with openpyxl as using

df2.to_excel(r'C:\BT\stack_test3.xls')

works which uses xlwt, I don't know enough about those packages so it could be either a permissions problem with openpyxl which I have not been able to find anything about or a bug.

like image 188
EdChum Avatar answered Dec 30 '22 12:12

EdChum