weighted_avg_by
The weighted_avg_by method creates a new table containing the weighted average for each group.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| wcol | str | The name of the weight column. |
| by optional | Union[str, list[str]] | The column(s) by which to group data.
|
Returns
A new table containing the weighted average for each group.
Examples
In this example, weighted_avg_by returns the weighted average of the whole table. Because an average cannot be computed for the string column Letter, this column is dropped before applying weighted_avg_by.
In this example, weighted_avg_by returns the weighted average, as grouped by X.