我想将表单合并不同的excel文件放在一起,所以我可以总结一下sheet1,sheet2等...但是现在我只能将表单分别放在一个工作簿中...任何帮助?谢谢你。
这是我的剧本:
import pandas as pd
import glob
import os
path_read =r'D:\merge'
list_dfs = []
data = pd.DataFrame()
for f in glob.glob(path_read + "/*.xls"):
sheets = pd.ExcelFile(f).sheet_names
for i,sheet in enumerate(sheets):
df = pd.read_excel(f, sheetname=sheets[i])
data = data.append(df)
list_dfs.append(data)
data = pd.DataFrame()
xls_path = r'D:\mytable.xlsx'
def save_xls(list_dfs, xls_path):
writer = pd.ExcelWriter(xls_path)
for n, df in enumerate(list_dfs):
df.to_excel(writer, 'sheet%s' % n)
writer.save()
save_xls(list_dfs,xls_path)