df.groupBy(color).max("count").show(); +-----------+----------+ |color |max(count)| +-----------+----------+ | red| 5| | blue| 3| | brown| 2| | green| 2| +-----------+----------+