【发布时间】:2021-12-31 01:33:45
【问题描述】:
我在 PySpark 中用这个表单创建了一个 rdd:
[(0, ('This', 1)), (0, ('is', 1)), (0, ('the', 1)), (0, ('100th', 1)), (0, ('Etext', 1)), (0, ('file', 1)), (0, ('presented', 1)), (0, ('by', 1)), (0, ('Project', 1)), (0, ('Gutenberg,', 1)), (0, ('and', 1)), (1, ('is', 1)), (1, ('presented', 1)), (1, ('in', 1)), (1, ('cooperation', 1)), (1, ('with', 1)), (1, ('World', 1)), (1, ('Library,', 1)), (1, ('Inc.,', 1)), (1, ('from', 1))]
对于第一个项目this 位于第一个row(0)。我加了1就可以得到频率了。
我找不到解决此问题的方法。使用aggregateByKey 或reduceByKey 后我期望的输出是例如:在第0 行,单词This 被使用了1 次等等......
[(0, ('This', 1, 'is', 1, 'the', 1, ...)), ...]
【问题讨论】:
标签: python pyspark rdd word-count