aggregate
Aggregates this Pivot using the provided statistics inside the AggregateDsl.
Returns a new DataRow with the original pivot keys as top-level columns on top level and the corresponding aggregated values in new nested columns.
AggregateDsl allows you to compute statistics on the columns within groups in Pivot and store the results as a new column using into. The given aggregating expression is applied to each group independently.
The resulting DataRow has the same structure as the original Pivot; instead of the groups, there are new columns of aggregated values created with into.
You can use any of DataFrame Aggregation Statistics or any custom aggregation function.
Aggregated values can be either simple values, data rows or even data frames. Including them in the result using into will lead to creating a value column, a column group, or a frame column respectively in the resulting DataRow while preserving the original structure at higher levels.
Check out for more information.pivot Grammar
For more information: See pivot on the documentation website.
Example
df.pivot { city }.aggregate {
// Сount rows within each pivot group and store the result
// into a new "total" column (a new sub-column under each key column)
count() into "total"
// Compute the maximum in "age" column within each group
// and store it into a new "maxAge" column
max { age } into "maxAge"
}Return
A new DataFrame with the results of the aggregation applied to each group.
Parameters
The aggregation logic defined using AggregateDsl.
Aggregates this GroupBy using the provided statistics inside the AggregateGroupedDsl.
Returns a new DataFrame with the original groupBy key columns and the corresponding aggregated values in new columns.
AggregateGroupedDsl allows you to compute statistics on the columns within groups in GroupBy and store the results as a new column using into. The given aggregating expression is applied to each group independently.
The resulting DataFrame has the same structure as the original GroupBy; instead of the groups, there are new columns of aggregated values created with into.
You can use any of DataFrame Aggregation Statistics or any custom aggregation function.
Aggregated values can be either simple values, data rows or even data frames. Including them in the result using into will lead to creating a value column, a column group, or a frame column respectively in the resulting DataFrame while preserving the original structure at higher levels.
It allows pivoting inside aggregate via corresponding methods:
Pivoting inside aggregate is useful for counting cross-group matrix-like statistics.
Check out for more information.groupBy Grammar
For more information: See groupBy on the documentation website.
Examples
df.groupBy { city }.aggregate {
// Сount rows within each group and store the result
// into a new "total" column
count() into "total"
// Compute the maximum in "age" column within each group
// and store it into a new "maxAge" column
max { age } into "maxAge"
}df.groupBy { name.firstName }.aggregate {
// Pivot the "city" column within each group,
// creating a PivotGroupBy with "name" as grouping keys
// and "city" as pivoted columns
pivot { city }.aggregate {
// Aggregate the mean of "age" column values for each
// "firstName" × "city" combination group into the "meanAge" column
mean { age } into "meanAge"
// Aggregate the size of each `PivotGroupBy` group
// into the "count" column
count() into "count"
}
// Common `count` aggregation
// into "total" column
count() into "total"
}Return
A new DataFrame with the results of the aggregation applied to each group.
Parameters
The aggregation logic defined using AggregateGroupedDsl.