PySpark groupByKey returning pyspark.resultiterable.ResultIterable

后端 未结 6 1245
不思量自难忘°
不思量自难忘° 2021-01-30 16:24

I am trying to figure out why my groupByKey is returning the following:

[(0, ), (1, 

        
6条回答
  •  孤城傲影
    2021-01-30 17:00

    Example:

    r1 = sc.parallelize([('a',1),('b',2)])
    r2 = sc.parallelize([('b',1),('d',2)])
    r1.cogroup(r2).mapValues(lambda x:tuple(reduce(add,__builtin__.map(list,x))))
    

    Result:

    [('d', (2,)), ('b', (2, 1)), ('a', (1,))]
    

提交回复
热议问题