Hello I am trying to pivot a data table similar to the table below and put the trouble code values and trouble code status into columns and group by job #
Source Table
I've tried following the example below with the following code
How to pivot on multiple columns in Spark SQL?
trouble_df = mydf.withColumn('combcol',F.concat(F.lit('trouble_code_'),mydf['trouble_code'])).groupby('Job #').pivot('combcol').agg(F.first('trouble_status'))
Below is the output from the code which isnt exactly what i'm looking. Fairly new to pyspark so still learning
Thank you for the help!


