How to write multiple pandas data frames to single output excel file? [duplicate]

a 夏天 提交于 2021-01-28 08:17:56

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/42562609/how-to-write-multiple-pandas-data-frames-to-single-output-excel-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!