Reducing
GroupBy reducing
Each GroupBy group can be collapsed into a single row and then concatenated into a new DataFrame composed of these rows.
Reducing is a specific case of aggregation.
First, choose a GroupBy reducing method:
first,last— take the first or last row (optionally, the first or last one that satisfies a predicate) of each group;minBy/maxBy— take the row with the minimum or maximum value of the givenRowExpressioncalculated on rows within each group;medianBy/percentileBy— take the row at the position closest to the estimated median/percentile index of theRowExpression's results calculated on rows within each group.
These functions return a ReducedGroupBy, which can then be transformed into a new DataFrame containing the reduced rows (either original or transformed) using one of the following methods:
concat— simply concatenates all reduced rows;values— creates aDataFramecontaining the values from the reduced rows in the selected columns.into— creates a new column with values computed withRowExpressionon each row, or a newcolumn groupcontaining each group reduced to a single row;
Each method returns a new DataFrame that includes the grouping key columns, containing all unique grouping key values (or value combinations for multiple keys) along with their corresponding reduced rows.
Check out .GroupBy grammar
For more information: See "GroupBy Reducing" on the documentation website.