dataFrame.rows — groupBy()

Description

The groupBy() method of the rows object Splits a DataFrame into multiple groups based on the selected columns. Each group is a new DataFrame containing a copy of the original header and all rows sharing the same values for the grouping columns.

Signature

dataFrame.rows.groupBy(...columnNames)
Scope
dataFrame
Family
rows
Returns
array

Argument

...columnNames (array)
The column names to identify unique combination of values.

Returns

groups (array)
An array of grouped DataFrames. Rows are partitioned according to the unique value combinations found in the selected columns. Each group preserves the original column structure.

Note

  • groupBy() creates groups, but does not aggregate them.
  • To calculate statistics for each group, iterate through the returned groups and apply the desired operations separately.

Example

// get groups of values from a dataFrame
var groups = dataFrame.rows.groupBy('country');

groups.forEach(function(group) {
    var group = groups[i];
    var country = group.cell('country', 1);
    var population = group.column('population').stat.sum();
    ...
});

notebook.output(groups);