I have several csv files that I want to merge to one file.
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')
It seems you need axis=1
parameter in concat
:
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames], sort=False, axis=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.