convert pyspark column to rows

Viewed 31

I have Table like this

|ID         |Attribute |value                |units
|1701321934 |RICHNESS  |0.5671775714285714   |FT
|1701321934 |VC        |0.18811              |PERCENT
|1701321934 |POR       |0.09997042857142857  |PERCENT

I wanted to achieve the following output, Each Attribute is pivoted and contains value

ID        |RICHNESS           |units|VC      |units  |POR                 |units         
1701321934|0.5671775714285714 |FT   |0.18811 |PERCENT|0.09997042857142857 |PERCENT

The data is in DataFrame and i am using the following code to pivot df.groupBy("ID").pivot("Attribute")

0 Answers
Related