📜  将多个 DataFrame 写入 Excel 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:29.175000             🧑  作者: Mango

代码示例1
# Write multiple DataFrames to Excel files
with pd.ExcelWriter('pandas_to_excel.xlsx') as writer:    
    df.to_excel(writer, sheet_name='sheet1')    
    df2.to_excel(writer, sheet_name='sheet2')
    
# Append to an existing Excel file    
path = 'pandas_to_excel.xlsx'
with pd.ExcelWriter(path) as writer:
    writer.book = openpyxl.load_workbook(path)
    df.to_excel(writer, sheet_name='new_sheet1')
    df2.to_excel(writer, sheet_name='new_sheet2')