Based on the following DataFrame:
DataFrame
val client = Seq((1,\"A\",10),(2,\"A\",5),(3,\"B\",56)).toDF(\"ID\",\"Categ\",\"Amnt\") +---+-----+----+ | ID|
You can do aggregation like below on given table:
client.groupBy("Categ").agg(sum("Amnt"),count("ID")).show() +-----+---------+---------+ |Categ|sum(Amnt)|count(ID)| +-----+---------+---------+ | A| 15| 2| | B| 56| 1| +-----+---------+---------+