Calculation(column, function, result_name=None)
Source¶
A statistic computed on a column of a Table, used by Aggregation.
Added in version 0.1.0
Parameters:
-
column(str)The name of the column.
-
function(Statistic)A
Statistic, such asndp.Mean()orndp.Quantile(0.9): seeStatisticfor every statistic. Missing values are ignored, unlessCountis set to include them. -
result_name(str | None, default:None)The name of the result column. When omitted, it is
<column>_<function>, such as"price_mean""price_quantile_90"or"price_count_excluded".
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
InvalidColumnNameErrorWhen
columnis an empty text. -
InvalidColumnNameErrorWhen
result_nameis an empty text. -
RefusedOperationErrorWhen
functionis not a statistic of numdaplot.
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})
total = ndp.Calculation(column="price", function=ndp.Sum())
highest = ndp.Calculation(column="price", function=ndp.Max(), result_name="highest_price")
sales.aggregate(ndp.Aggregation(calculations=[total, highest]))
# price_sum highest_price
# FLOAT64 FLOAT64
# 0 350.0 150.0