Home > Back-end >  Transformation and coding in Pyspark or Scala scenario
Transformation and coding in Pyspark or Scala scenario

Time:10-09

I have a situation in my json file I have two columns eventid & sectionname which is dynamic in nature. As mentioned in diagram input

enter image description here enter image description here

I need output like this which transformation I can perform and since section name is dynamic i.e instead of 301 it will come 501 also in future & I don't want my stream to fail is there any way in pyspark or scala. enter image description here

CodePudding user response:

df_target = (df_source.set_index(list of static columns)
  .rename_axis([New_Column_Name], axis=1)
  .stack()
  .reset_index())

Where df_source is your dataframe in pandas

  • Related