Home » Python » python – AttributeError: 'NoneType' object has no attribute 'save' while saving DataFrame to xls-Exceptionshub

python – AttributeError: 'NoneType' object has no attribute 'save' while saving DataFrame to xls-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have a DataFrame received by .concat and I am to save it as xls file, but I get AttributeError: 'NoneType' object has no attribute 'save' Here is a screen of my Dataframe and my code for xls: screen

writer = pd.ExcelWriter('data.xls', engine='xlsxwriter')
data = data.to_excel(writer)
data.save()

in which moment and how can I fix this?

How to&Answers:

The pandas to_excel method returns None.

data = data.to_excel(writer)

This overwrites your dataframe with None, which doesn’t have a save() function.

Try doing this, which should work:

writer = pd.ExcelWriter('data.xls', engine='xlsxwriter')
data.to_excel(writer)
writer.save()