python - 合并 pySpark RDD 中的列表列表

标签 python apache-spark pyspark

我有一些元组列表,我想将它们组合成一个列表。我已经能够使用 lambdas 和列表理解来处理数据,直到我接近能够使用 reduceByKey 但不确定如何合并列表。所以格式...

[[(0, 14), (0, 24)], [(1, 19), (1, 50)], ...]

我希望它是这样的......

[(0, 14), (0, 24), (1, 19), (1, 50), ...]

让我到达目的地的代码...

test = test.map(lambda x: (x[1], [e * local[x[1]] for e in x[0]]))
test = test.map(lambda x: [(x[0], y) for y in x[1]])

但不确定如何合并列表

最佳答案

你可以做到,

test = test.flatMap(identity)

test = test.flatMap(lambda list: list)

关于python - 合并 pySpark RDD 中的列表列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46556327/

相关文章:

python - 运行 Pyspark 程序时出现 Py4JJavaError

hadoop - YARN最小用户限制百分比不起作用?

python - 使用 Spark 获取值超过某个阈值的所有列的名称

python - 使用 base64 从 JSON 中获取二进制文件

python - 当我希望在两个 setText 之间做某事时,pyqt5 QLineEdit.setText 仅在功能中工作一次

scala - 在 Spark Scala 中使用 map() 重新排序键值对

python - 数据框 pyspark 到 dict

pyspark - 动态框架写入额外的列

python - 使用 Pandas 将 groupby 聚合应用于原始数据框

python - Scipy 未安装在 Windows 机器上