I have a dataframe with 3 columns as shown below
I would like to Pivot and fill the columns on the id so that each row contains a column for each id + column combination where the value is for that id, as shown below
Note: Zero or Null is shown if the ID does not match. For instance ID2_colA and Id2_ColB get 0 in the first two rows, and ID1_calA abd ID1_ColB get 0 in row 3
There are more distinct values in ID column. Shortened it for the ease of illustration
How can I achieve this in pyspark?
Here is the code for the first dataframe:
data = [(("ID1", 3, 5)), (("ID1", 4, 12)), (("ID2", 8, 3))]
df = spark.createDataFrame(data, ["ID", "colA", "colB"])

