| title | count_ |
|---|
agg.count_ returns an aggregator that computes the number of elements within an aggregation group.
Note
count is a reserved Python keyword, so an underscore is used to maintain Python conventions.
count_(col: str) -> Aggregation
The name of the output column that will contain the number of elements in each group.
An aggregator that computes the number of elements within an aggregation group, for each group.
In this example, agg.count adds a count column, Number, while agg.avgreturns the average Number, as grouped by X.
from deephaven import new_table
from deephaven.column import string_col, int_col, double_col
from deephaven import agg as agg
source = new_table(
[
string_col("X", ["A", "B", "A", "C", "B", "A", "B", "B", "C"]),
string_col("Y", ["M", "P", "O", "N", "P", "M", "O", "P", "N"]),
int_col("Number", [55, 76, 20, 130, 230, 50, 73, 137, 214]),
]
)
result = source.agg_by(
[agg.count_(col="Number"), agg.avg(cols="AvgNum = Number")], by=["X"]
)