import pandas as pd

df1 = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]}, columns=['a', 'b'])
df2 = pd.DataFrame({'a':[7,8,9], 'b':[6,5,4]}, columns=['a', 'b'])

def write_last_sheet():
df1.to_excel('output2.xlsx', sheet_name='Sheet1', startcol=0, index=False)
df2.to_excel('output2.xlsx', sheet_name='Sheet2', startcol=0, index=False)

def write_multi_sheet():
write = pd.ExcelWriter('output1.xlsx')
df1.to_excel(write, sheet_name='Sheet1', startcol=0, index=False)
df2.to_excel(write, sheet_name='Sheet2', startcol=0, index=False)
write.save()

write_last_sheet()
write_multi_sheet()
文档更新时间: 2020-09-02 02:16   作者:月影鹏鹏