write multiple dataframes to excel files

Solutions on MaxInterview for write multiple dataframes to excel files by the best coders in the world

showing results for - "write multiple dataframes to excel files"
Paddy
12 Jan 2017
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')