合并指定文件夹内的所有工作簿
代码实现
import os
import pandas as pd
folderPath = r"./需要合并的文件丢进来" # 指定的文件夹路径即包含你需要的文件所在的文件夹
liPath = os.listdir(folderPath)
print(liPath)
all_files = []
for file in liPath:
try:
filePath = os.path.join(folderPath, file)
df = pd.read_excel(filePath)
except:
filePath = os.path.join(folderPath, file.replace('.xlsx', '.xls'))
df = pd.read_excel(filePath)
all_files.append(df)
reAll = pd.concat(alldfs)
print(reAll)
reAll.to_excel("reALL.xlsx", index=None)