Aggregation(calculations=None, group_by=None, row_count=None)
Source¶
Statistics computed on the whole Table or on each group of rows, used by Table.aggregate.
Added in version 0.1.0
Changed in version 0.2.0
Adds row_count, and calculations becomes optional. The error for a repeated result name advises a
result_name for each calculation.
Parameters:
-
calculations(list[Calculation] | None, default:None)The statistics to compute. The aggregation keeps its own copy of the list. None when omitted, then
row_countis required. -
group_by(list[str] | None, default:None)The names of the columns whose values form the groups: one result row per combination of values. The whole Table gives a single row when omitted.
-
row_count(str | None, default:None)The name of a column giving the number of rows of each group, placed right after the group columns. No such column when omitted.
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
EmptyAggregationErrorWhen neither
calculationsnorrow_countis given. -
EmptyListErrorWhen
calculationsorgroup_byis an empty list. -
InvalidColumnNameErrorWhen a group column name or
row_countis an empty text. -
DuplicateColumnErrorWhen a name appears twice among the group columns,
row_countand the result names.
Examples:
import numdaplot as ndp
cities = ndp.Array.from_list(["Paris", "Lyon", "Paris"])
prices = ndp.Array.from_list([120.0, 80.0, 150.0])
sales = ndp.Table.from_arrays({"city": cities, "price": prices})
average_price = ndp.Calculation(column="price", function=ndp.Mean())
sales.aggregate(ndp.Aggregation(calculations=[average_price], group_by=["city"], row_count="sale_count"))
# city sale_count price_mean
# TEXT INT64 FLOAT64
# 0 Lyon 1 80.0
# 1 Paris 2 135.0