pythondataframeexport-to-excelxlsnonetype

AttributeError: 'NoneType' object has no attribute 'save' while saving DataFrame to xls


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?


Solution

  • 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()