Reputation: 13969
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'
Upvotes: 4
Views: 13380
Reputation: 1
After closing all instances of excel and running python code works.
Upvotes: -1
Reputation: 43
To confirm...in case future readers stumble in this page...before complicating things make sure that the excel file you are trying to save is not already open or to be safe.
Just close all of excel and try save it again.
That should do it.
Upvotes: 1
Reputation: 285
I had an identical problem. Turns out it's because I had left the Excel file open whilst I was trying to write to it. Apparently it doesn't like that. If you have it open try closing it.
Upvotes: 4
Reputation: 393863
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.
Upvotes: 9
Reputation: 428
You should write to another drive like 'D:' because in Windows Vista or above that you have no permission to write to 'C:\' and you have no reason to earn the permission.
Upvotes: 0