Search code examples
pythonpandasxlsxwriter

Permission error when pandas dataframe is write to xlsx file


I get this error while i want to keep my dataframe in excel file which name pandas_simple.xlsx

Below is my error:

enter image description here

This is my code:

import pandas as pd
df = pd.DataFrame({'Car': [101, 20, 350, 20, 15, 320, 454]})
writer = pd.ExcelWriter('pandas_simple.xlsx')
df.to_excel(writer, sheet_name='Sheet1')
writer.save()
writer.close()

Anyone can share some idea to me here?


Solution

  • You try to write to a folder where you need administration rights. Change:

    writer = pd.ExcelWriter("pandas_simple.xlsx")
    

    to:

    writer = pd.ExcelWriter("C:\\...\\pandas_simple.xlsx")
    

    with the full path and you will not have a problem.