将工作表从一个工作簿循环移动到另一个工作簿

时间:2020-02-07 06:13:31

标签: python excel python-3.x pandas xlsx

import pandas as pd
xl_dict = {}
sheetname_list = ['2018', '2019', '2020']
#i am able to get the sheets from here
for sheet in sheetname_list:
    xl_dict[sheet] = pd.read_excel('Mvvvv Ds.xlsx', sheet_name=sheet)
    print(xl_dict[sheet].title)

无法在此文件中添加工作表,我想在此文件中添加添加这三张工作表。

path2 = '2020-01-29.xlsx'

1 个答案:

答案 0 :(得分:0)

我认为您应该签出Excel Writer

writer = pd.ExcelWriter(path2)
[xl_dict[sheetname_list[x]].to_excel(writer,sheet_name=sheetname_list[x]) for x in range(len(sheetname_list))]
writer.save()