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