简体   繁体   中英

I want to add a new sheet in an excel created using .to_excel in pandas

This is my code, how do I add another data frame to the same excel, say: 'df3', but on a different sheet:

df2.to_excel('Invoicing Detail Output File.xlsx', index = False)

Write directly to a new excel ( see ):

with pd.ExcelWriter('Invoicing Detail Output File.xlsx') as writer:
    df2.to_excel(writer, sheet_name='Sheet1')
    df3.to_excel(writer, sheet_name='Sheet2')

Or append to existing excel:

with ExcelWriter('Invoicing Detail Output File.xlsx', mode='a') as writer:
    df3.to_excel(writer, sheet_name='Sheet2')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM