pandas写多个sheet到同一个excel

pandas写多个sheet到同一个excel

#enter code here
# dataframe: 需要写入excel的数据
# outfile:输出的文件地址
# name: sheet_name的文件名称
def excelAddSheet(dataframe, outfile, name):
    writer = pd.ExcelWriter(outfile, enginge='openpyxl')
    if os.path.exists(outfile) != True:
        dataframe.to_excel(writer, name, index=None)
    else:
        book = load_workbook(writer.path)
        writer.book = book
        dataframe.to_excel(excel_writer=writer, sheet_name = name, index=None)
    writer.save()
    writer.close()

效果就是该方法能够将不同的dataFrame写入同一个excel的不同sheet。

你可能感兴趣的:(python)