import os
import pandas as pd
pwd = r'C:\Users\chenl\Desktop\睿智\需求文档\评分业务\D3分\FICO_SCORE_D3_history'
#新建文件列表,存放文件名
file_list =[]
#新建列表存放每个文件得数据
dfs = []
#os.walk 遍历目录内的各个子目录和文件
for root, dirs, files in os.walk(pwd): # 第一个为起始路径,第二个为起始路径下的文件夹,第三个是起始路径下的文件。
for file in files:
file_path = os.path.join(root, file)
file_dt=file_path[-12:-4]
df = pd.read_csv(file_path) # 将excel转换成DataFrame
df['dt'] = file_dt
#file_list.append(file_path) # 使用os.path.join(dirpath, name)得到全路径
print(df)
dfs.append(df)
# 将多个DataFrame合并为一个
df = pd.concat(dfs)
df.to_csv(r'C:\Users\chenl\Desktop\SS.csv',index=False)
# 写入excel文件,不包含索引数据