sum_by
sum_by returns the total sum for each group. Null values are ignored.
Caution
Applying this aggregation to a column where the sum can not be computed will result in an error. For example, the sum is not defined for a column of string values.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| by optional | Union[str, list[str]] | The column(s) by which to group data.
|
Returns
A new table containing the sum for each group.
Examples
In this example, sum_by returns the sum of the whole table. Because a sum can not be computed for the string columns X and Y, these columns are dropped before applying sum_by.
In this example, sum_by returns the sum, as grouped by X. Because a sum can not be computed for the string column Y, this column is dropped before applying sum_by.
In this example, sum_by returns the sum, as grouped by X and Y.