多个dataframe合并,读取多个csv文件进行合并

方法1:

import pandas as pd
import os

output_file = 'D:/PycharmProjects/DataProcess/MeteData/out/AllYear_'
input_path = 'D:/PycharmProjects/DataProcess/MeteData/out/v10/'

files = os.listdir(input_path)
all_data_frames = []
for file in files:
    data_frame = pd.read_csv(input_path+file, index_col=None)
    all_data_frames.append(data_frame)

data_frame_concat = pd.concat(all_data_frames, axis=0, ignore_index=True)
data_frame_concat.to_csv(output_file+file, index=False)

方法2:

import pandas as pd
import os

filepath = 'D:\\PycharmProjects\\DataProcess\\Check_MatchResult\\'
outpath = 'C:\\Users\\user\\Desktop\\testout.csv'

allfile = os.listdir(filepath)
features = pd.DataFrame()
for file in allfile:
    feature = pd.read_csv(filepath + file, encoding='ANSI')
    features = features.append(feature)

features.to_csv(outpath, index=False)

 

你可能感兴趣的:(#,Python,python,csv)