Aggregation
GroupBy aggregation
Each GroupBy can be directly transformed into a new DataFrame by applying one or more aggregation operations to its groups.
Aggregation is a generalization of reducing.
The following aggregation methods are available:
concat— concatenates all rows from all groups into a singleDataFrame, without preserving grouping keys;toDataFrame— returns thisGroupByasDataFramewith the grouping keys and corresponding groups inFrameColumn.concatWithKeys— a variant ofconcatthat also includes grouping keys that were not present in the originalDataFrame;into— creates a new column containing a list of values computed with aRowExpressionfor each group, or a newframe columncontaining the groups themselves;values— creates aDataFramecontaining values collected into a singleListfrom all rows of each group for the selected columns.count— creates aDataFramecontaining the grouping key columns and an additional column with the number of rows in each corresponding group;countDistinct— creates aDataFramecontaining the grouping key columns and an additional column with the number of distinct rows in each corresponding group;aggregate— performs a set of custom aggregations usingAggregateDsl, allowing you to compute one or more derived values per group;Various aggregation statistics— predefined shortcuts for common statistical aggregations such assum,mean,median, and others.
Each of these methods returns a new DataFrame that includes the grouping key columns (except for concat) along with the columns of values aggregated from the corresponding groups.
Check out .GroupBy grammar
For more information: See "GroupBy Aggregation" on the documentation website.