takeOrdered descending Pyspark

前端 未结 1 1164

i would like to sort K/V pairs by values and then take the biggest five values. I managed to do this with reverting K/V with first map, sort in descending order with FALSE, and

相关标签:
1条回答
  • 2021-01-31 17:51

    Sort by keys (ascending):

    RDD.takeOrdered(5, key = lambda x: x[0])
    

    Sort by keys (descending):

    RDD.takeOrdered(5, key = lambda x: -x[0])
    

    Sort by values (ascending):

    RDD.takeOrdered(5, key = lambda x: x[1])
    

    Sort by values (descending):

    RDD.takeOrdered(5, key = lambda x: -x[1])
    
    0 讨论(0)
提交回复
热议问题