1、导入包import osimport pandas as pdimport openpyxlimport warningswarnings.filterwarnings("ignore")
2、添加源文件地址,获取文件名dir = "./源文件"filenames = os.listdir(dir)print(filenames)
3、新增空list,遍历文件appen蟠校盯昂d到空列dfs = []df1 = []for name in file荏鱿胫协names: print(name) df1 = pd.read_excel(os.path.join(dir, name)) username = name df1['文件名'] = username dfs.append(df1)
4、合并文件名列,表示墙绅褡孛数据来源,后保存合并后的文件df = pd.concat(dfs,ignore_足毂忍珩index=True)df.to_excel('./合并文件.xlsx', index=False)