标签:result mod pre port for dir nbsp path except
#encoding=utf-8 import pandas as pd import os import csv def concat_csv(filename,dirpath): with open(filename,‘w‘) as f: cw=csv.writer(f) cw.writerow([‘column1‘,‘column2‘]) for inputfile in os.listdir(dirpath): order=[‘column1‘,‘column2‘] df=pd.read_csv(dirpath+inputfile,encoding=‘utf-8-sig‘) try: # 对字段进行排序 df=df[order] df.to_csv(filename, mode=‘a‘, index=False, header=False,encoding=‘utf-8-sig‘) except Exception as e: print(e,inputfile,df.columns) if __name__==‘__main__‘: filename=‘result.csv‘ dirpath=‘d:/‘ concat_csv(filename,dirpath)
标签:result mod pre port for dir nbsp path except
原文地址:https://www.cnblogs.com/Monkey18/p/14866209.html