如果我有一个键/值的 RDD(键是列索引),是否可以将它加载到数据帧中?
例如:
(0,1), (0,1), (0,2), (1,2), (1,10), (1,20), (3,18), (3,18), (3,18)
并让数据框看起来像:
1,2,18
1,10,18
2,20,18
最佳答案
是的,这是可能的(用 Spark 1.3.1 测试):
>>> rdd = sc.parallelize([(0,1), (0,1), (0,2), (1,2), (1,10), (1,20), (3,18), (3,18), (3,18)])
>>> sqlContext.createDataFrame(rdd, ["id", "score"])
Out[2]: DataFrame[id: bigint, score: bigint]
关于apache-spark - pySpark 使用键/值从 RDD 创建数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30007200/