我有几个要合并到一个文件的csv文件。
import os
import glob
import pandas as pd
os.chdir('/home/yovel/PycharmProjects/fantasyfinal/stats')
extension = 'csv'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames], sort=False)
combined_csv.to_csv("statsmerger.csv", index=True, encoding='utf-8-sig')
答案 0 :(得分:1)
似乎您需要在concat
中使用axis=1
参数:
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames], sort=False, axis=1)