多个 pandas 数据框的交集 [英] Intersection of multiple pandas dataframes

查看:88
本文介绍了多个 pandas 数据框的交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表中有多个数据帧(100),如下所示:

I have a number of dataframes (100) in a list as:

frameList = [df1,df2,..,df100]

每个数据框都有两列DateTimeTemperature.

Each dataframe has the two columns DateTime, Temperature.

我要与公共DateTime列上的所有数据框相交,并将它们的所有Temperature列组合/合并为一个大数据框:df1的温度,df2的温度,df3的温度,..,df3的温度df100.

I want to intersect all the dataframes on the common DateTime column and get all their Temperature columns combined/merged into one big dataframe: Temperature from df1, Temperature from df2, Temperature from df3, .., Temperature from df100.

(熊猫merge无法正常工作,因为我必须计算多个(99)两两交叉点.)

(pandas merge doesn't work as I'd have to compute multiple (99) pairwise intersections).

推荐答案

使用pd.concat,它适用于DataFrame或Series列表.

Use pd.concat, which works on a list of DataFrames or Series.

pd.concat(frameList, axis=1, join='inner')

这比使用pd.merge更好,因为pd.merge每次执行时都会成对复制数据. pd.concat仅复制一次.但是,pd.concat仅基于轴合并,而pd.merge也可以在(多个)列上合并.

This is better than using pd.merge, as pd.merge will copy the data pairwise every time it is executed. pd.concat copies only once. However, pd.concat only merges based on an axes, whereas pd.merge can also merge on (multiple) columns.

这篇关于多个 pandas 数据框的交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆