📜  python 合并同一文件夹中的 csv 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:58.980000             🧑  作者: Mango

代码示例1
import os, glob
import pandas as pd

os.chdir(os.path.dirname(__file__) + r"\CSVs")

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 ])

os.chdir(os.path.dirname(__file__))

combined_csv.to_csv( "combined_csv.csv", index=False, encoding='utf-8-sig')