3

I am currently working on Python3 and have a large number of related pandas dataframes. I need to write it to single excel file with each dataframe as a separate tab, I can write all of them separately to excel files and then copy, paste them to a single file. However, I am looking for a more automated solution to the problem. Thanks in advance for the help.

Alex.Widmore
  • 71
  • 2
  • 5

1 Answers1

5

Here is code that does that for you:

fname = 'foobar.xlsx'
writer = pd.ExcelWriter(fname)
df1.to_excel(writer, "sheet1", index=False)
df2.to_excel(writer, "sheet2", index=False)
## more dataframes goes here
writer.save()
Dataman
  • 3,457
  • 3
  • 19
  • 31