0

I have a Pandas/PySpark dataframe like this.

enter image description here

I want to convert this into the below format.

enter image description here

Tried using PySpark with below code

df2 = df.groupBy('id').agg( F.to_json( F.collect_list( F.create_map( 'Details','Values' ) ) ).alias('Attributes'))

df2.show(truncate=False)

Ramineni Ravi Teja
  • 2,967
  • 22
  • 32

0 Answers0