How to pivot on multiple columns in Spark SQL?

后端 未结 3 1290
梦毁少年i
梦毁少年i 2020-12-13 20:01

I need to pivot more than one column in a pyspark dataframe. Sample dataframe,

 >>> d = [(100,1,23,10),(100,2,45,11),(100,3,67,12),(100,4,78,13),(10         


        
3条回答
  •  失恋的感觉
    2020-12-13 20:29

    The solution in the question is the best I could get. The only improvement would be to cache the input dataset to avoid double scan, i.e.

    mydf.cache
    pivot_udf(mydf,'price','units').show()
    

提交回复
热议问题