weighted_sum_by

The weighted_sum_by method creates a new table containing the weighted sum for each group.

Syntax

Parameters

ParameterTypeDescription
wcolstr

The name of the weight column.

by optionalUnion[str, list[str]]

The column(s) by which to group data.

  • [] returns the weighted sum for all non-key columns (default).
  • ["X"] will output the weighted sum of each group in column X.
  • ["X", "Y"] will output the weighted sum of each group designated from the X and Y columns.

Returns

A new table containing the weighted sum for each group.

Examples

In this example, weighted_sum_by returns the weighted sum of the whole table. Because a sum cannot be computed for the string column Letter, this column is dropped before applying weighted_sum_by.

In this example, weighted_sum_by returns the weighted sum, as grouped by X.