cpd*_*pd1 2 python apache-spark pyspark
我有要组合成一个列表的元组列表。我已经能够使用lambda和列表理解来处理数据,而我几乎可以使用reduceByKey但不确定如何合并列表。所以格式...
[[(0, 14), (0, 24)], [(1, 19), (1, 50)], ...]
Run Code Online (Sandbox Code Playgroud)
我希望是这样...
[(0, 14), (0, 24), (1, 19), (1, 50), ...]
Run Code Online (Sandbox Code Playgroud)
使我到达需要的地方的代码...
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]])
Run Code Online (Sandbox Code Playgroud)
但是不确定从那里开始如何合并列表
你可以做,
test = test.flatMap(identity)
Run Code Online (Sandbox Code Playgroud)
要么
test = test.flatMap(lambda list: list)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2393 次 |
| 最近记录: |