Skip to content Skip to sidebar Skip to footer

Write Multiple Pandas Dataframes To Excel

I am attempting to write multiple pandas dataframes which I extracted from a larger dataset into multiple worksheets of an excel workbook. The issue is that it only writes the firs

Solution 1:

You need to call writer.save() after the for construct.

Once this method is called, the writer object is effectively closed and you will not be able to use it to write more data.

writer = ExcelWriter('test_output.xlsx')
for n, df inenumerate(df_list):
    df.to_excel(writer, 'sheet%s' % str(n + 1))
writer.save()

Post a Comment for "Write Multiple Pandas Dataframes To Excel"