I have a DataFrame generated as follow:
df.groupBy($\"Hour\", $\"Category\") .agg(sum($\"value\") as \"TotalValue\") .sort($\"Hour\".asc, $\"TotalValue\"
Here you can do like this -
val data = df.groupBy("Hour").agg(first("Hour").as("_1"),first("Category").as("Category"),first("TotalValue").as("TotalValue")).drop("Hour") data.withColumnRenamed("_1","Hour").show