我有一个类似于以下示例的DataFrame:
Timestamp | Word | Count
30/12/2015 | example_1 | 3
29/12/2015 | example_2 | 1
28/12/2015 | example_2 | 9
27/12/2015 | example_3 | 7
... | ... | ...
我想按“字”列的值拆分此数据框以获得“数据框”的“列表”(以便在下一步中绘制一些图形)。例如:
DF1
Timestamp | Word | Count
30/12/2015 | example_1 | 3
DF2
Timestamp | Word | Count
29/12/2015 | example_2 | 1
28/12/2015 | example_2 | 9
DF3
Timestamp | Word | Count
27/12/2015 | example_3 | 7
有没有办法用PySpark(1.6)做到这一点?
效率不高,但是您可以使用过滤器映射到唯一值列表:
words = df.select("Word").distinct().flatMap(lambda x: x).collect()
dfs = [df.where(df["Word"] == word) for word in words]
发布Spark 2.0
words = df.select("Word").distinct().rdd.flatMap(lambda x: x).collect()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句