代码:
import pandas as pd
import glob
target_path = 'Dataset/target.csv'
cat_list = glob.glob('Dataset/cat/*csv')
for index, cat_csv in enumerate(cat_list):
data = pd.read_csv(cat_csv)
if index == 0:
# 第一个文件写入表头
data.to_csv(target_path, index=False,header=True)
else:
# 不写表头
data.to_csv(target_path, index=False, header=False, mode='a+')
print('ok')
标签:文件,target,index,glob,cat,拼接,path,csv
From: https://www.cnblogs.com/odesey/p/16993425.html