GroupByDocs

internal interface GroupByDocs

Groups the rows of this DataFrame based on the values in one or more specified cols. Each unique value in a key column — or a unique tuple of values for multiple columns — defines the group consisting of all rows where the column(s) contain that value combination.

Returns a GroupBy — a dataframe-like structure that contains all unique combinations of key values along with the corresponding groups of rows (each represented as a DataFrame) as rows.

A GroupBy can then be:

Grouping keys can also be created inline (i.g. by creating a new column using expr or simply renaming the old one using named):

// Create a new column "newName" based on existing "oldName" values
// and use it as a grouping key:
df.groupBy { expr("newName") { oldName.drop(5) } }

Check out Grammar.

This can include column groups and nested columns.

See Selecting Columns.

For more information: See groupBy on the documentation website.

Don't confuse this with group, which groups column into column group.

See also pivot that groups rows of DataFrame vertically.

Types

Link copied to clipboard
typealias Aggregation = Nothing

Each GroupBy can be directly transformed into a new DataFrame by applying one or more aggregation operations to its groups.

Link copied to clipboard

Provides predefined shortcuts for the most common statistical aggregation operations that can be applied to each group within a GroupBy.

Link copied to clipboard
typealias Grammar = Nothing
Link copied to clipboard

Selecting columns for various DataFrame operations can be done in the following ways:

Link copied to clipboard
typealias Mapping = Nothing

Instead of aggregating the groups, a GroupBy can be walked over key–group pair by key–group pair, with the result of a lambda collected for each of them. Every pair is given to the lambda as a GroupWithKey, so its key values are available as key and its rows as group.

Link copied to clipboard
typealias Pivoting = Nothing

GroupBy can be pivoted with pivot method. It will produce a PivotGroupBy.

Link copied to clipboard
typealias Reducing = Nothing

Each GroupBy group can be collapsed into a single row and then concatenated into a new DataFrame composed of these rows.

Link copied to clipboard

A GroupBy can be transformed into a new GroupBy using one of the following methods: