合并pySpark RDD中的列表列表
问题内容:
我有要合并成一个列表的元组列表。我已经能够使用lambda和列表理解来处理数据,而我几乎可以使用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)