合并文件夹下的所有excel文件

import pandas as pd
import os

path = r".\excel表格"
# 获取该目录下所有文件,存入列表中
fileList = os.listdir(path)

n = 0
all_df = pd.DataFrame()
for i in fileList:
    file_path = path + os.sep + fileList[n]
    df = pd.read_excel(file_path)
    all_df = pd.concat([all_df, df])
    n += 1

all_df.to_excel("all.xlsx", index=False)
posted @ 2022-11-09 10:32  tiansz  阅读(100)  评论(0)    收藏  举报