多个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)

 

    原文作者:ch206265
    原文地址: https://blog.csdn.net/ch206265/article/details/106628380
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞