import pandas as pd import os #文件路径注意用\ inputfilepath = "D:Users/myapp/ccd/" outputfilepath ="D:Users/myapp/ccd/" df_filename = "2020-08-31.csv" columns_list = ['时间', '阳极左', '阳极右', '阴极左', '阴极右', '隔膜左', '隔膜右', '阳极中', '阴极中', '隔膜中', '阴阳中心线差', '阳极宽度', '阴极极宽度', '隔膜宽度', '阳极放卷轴', '阴极放卷轴', '上隔膜放卷轴', '下隔膜放卷轴', '阳左_阴左', '阳左_隔左', 'CPC功能', '插片角度功能'] #先创建一个只有表头列名的空dataframe,保存为csv df = pd.DataFrame(columns = columns_list) df.to_csv(outputfilepath + df_filename,encoding="utf_8_sig") #遍历输入路径文件夹,用pandas读取后追加在目标csv文件中 for inputfile in os.listdir(inputfilepath): df = pd.read_csv(inputfilepath+inputfile,encoding='gbk',error_bad_lines=False) df.to_csv(outputfilepath + df_filename, mode="a", index=True,header = False) #查看合并后的表格 pd.read_csv(outputfilepath + df_filename)