PySpark reduceByKey on multiple values

前端 未结 1 948
轻奢々
轻奢々 2021-01-23 16:41

If I have a K,V pair that is like:

(K, (v1, v2))
(K, (v3, v4))

How can I sum up the values such that I get (k, (v1 + v3, v2 + v4))

1条回答
  •  不要未来只要你来
    2021-01-23 17:38

    reduceByKey supports functions. Lets say A is the array of the Key-Value pairs.

    output = A.reduceByKey(lambda x, y: x[0]+y[0], x[1]+y[1])
    

    0 讨论(0)
提交回复
热议问题