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

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值