我有一个dataframe(或者可以是任何RDD),它在一个众所周知的模式中包含数百万行:
Key | FeatureA | FeatureB
--------------------------
U1 | 0 | 1
U2 | 1 | 1
我需要从磁盘上加载十几个其他数据集,这些数据集包含相同数量密钥的不同特性。有些数据集的宽度可达十几列。想象一下:
^{pr2}$这感觉像是一个折叠或积累,我只想迭代所有的数据集,然后得到这样的结果:
Key | FeatureA | FeatureB | FeatureC | FeatureD | FeatureE | FeatureF
---------------------------------------------------------------------
U1 | 0 | 1 | 0 | 0 | 1 | 0
U2 | 1 | 1 | 0 | 0 | 0 | 1
我尝试过加载每个数据帧然后加入,但是一旦我通过了一些数据集,那就花了很多时间。我是否缺少完成这项任务的共同模式或有效方式?在
假设每个
DataFrame
中每个键最多有一行,并且所有键都是基元类型,则可以尝试使用聚合进行联合。让我们从一些导入和示例数据开始:接下来我们可以提取公共模式:
^{pr2}$并转换所有
DataFrames
:最后是一个联合和虚拟聚合:
如果每个键有多行,但个别列仍然是原子的,则可以尝试将}。在
max
替换为collect_list
/collect_set
,后跟{相关问题 更多 >
编程相关推荐