0
Parameter Value Data_type
window 1024 Data1
noverlap 256 Data1
ylim_min 0 Data1
ylim_max 500 Data1
mag_min 0 Data1
max_max 30 Data1
window 2500 Data2
noverlap 64 Data2
ylim_min 0 Data2
ylim_max 50 Data2
mag_min 0 Data2
mag_max 2500 Data2

How do I transpose this pyspark data frame such as:

enter image description here

Comsavvy
  • 630
  • 9
  • 18
emma19
  • 57
  • 2
  • 7

1 Answers1

0

It is almost same as pandas dataframe

Let the dataframe is df

pivotdf= df.groupBy("Data_Type").pivot("Parameter").sum("Value")
pivotdf.show()

Here we are pivoting the column Parameter by grouping the column Data_Type

  • Thank you for the reply. After that I was actually trying to filter the pyspark dataframe by taking like rows from 40 to 50. The limit function will only take like first n rows. Is there a way to chunk the dataframe with a range? Example: like this df=df.limit[40:50] – emma19 Feb 19 '21 at 19:00
  • @emma19 As you need specific range `df.collect()[2:5]` but it will not give the output as dataframe format If you are looking for a dataframe format then try like this `df.toPandas()[2:5]` but if I am not wrong this will lose the distributed properties of spark but gives nice formatting – Midhilesh Momidi Feb 19 '21 at 21:34