将熊猫DF粘贴到特定表格中已存在的工作簿中

时间:2019-02-04 12:29:18

标签: python-3.x

我有一个名为test.xlsx的Excel文件。这个Excel包含几个工作表- 周一,周二,周三,周四,三。我想将mon数据框粘贴到Mon的test.xlsx中。但是下面的代码将创建另一个名为mon1的工作表,依此类推。

下面是我的代码

from openpyxl import load_workbook

path = 'test.xlsx'

book = load_workbook(path)

writer.book = book

with pd.ExcelWriter(path, engine='openpyxl') as writer:

    writer.book = load_workbook(path)

raw_excel.to_excel(writer, sheet_name = 'raw_output')

mon.to_excel(writer, 'mon')

tue.to_excel(writer, 'tue')

wed.to_excel(writer, 'wed')

thu.to_excel(writer, 'thu')

writer.save()

writer.close()

0 个答案:

没有答案