'Forming multiple columns from data in a perticular column based on condition in PySpark

I have a spark daframe like

item_id   attribute_id  attribute_value
1001      color          blue
1001      shape          rectangular
1001      material       copper
1002      color          black
1002      material       copper
1003      color          grey

I Want Resultant dataframe to match below

item_id   color    shape        meterial 
1001      blue     rectangular  copper
1002      black    null         copper
1003      grey     null         null

I am trying achieve this in PySpark but not sure about the syntax, Any Hints? Note: Any pointers in PySpark or spark sql is appreciated



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source