from pyspark.sql.functions import * from pyspark.sql import Window var win = Window.partitionBy("date") data.withColumn("max_vol",max("volume").over(win)).groupBy("date","max_vol") .pivot("recipe") .agg(avg("percent")).show()