1# Write multiple DataFrames to Excel files
2with pd.ExcelWriter('pandas_to_excel.xlsx') as writer:
3 df.to_excel(writer, sheet_name='sheet1')
4 df2.to_excel(writer, sheet_name='sheet2')
5
6# Append to an existing Excel file
7path = 'pandas_to_excel.xlsx'
8with pd.ExcelWriter(path) as writer:
9 writer.book = openpyxl.load_workbook(path)
10 df.to_excel(writer, sheet_name='new_sheet1')
11 df2.to_excel(writer, sheet_name='new_sheet2')