count_where
agg.count_where returns an aggregator that computes the number of values that pass a set of filters within an aggregation group.
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
| col | str | The name of the column that will contain the count of values that pass the filters. |
| filters | Union[str, Filter, Sequence[str], Sequence[Filter]] | Formulas for filtering as a list of Strings. Filters can be:
|
Tip
Providing multiple filter strings in the filters parameter will result in an AND operation being applied to the
filters. For example,
"Number % 3 == 0", "Number % 5 == 0" will return the count of values where Number is evenly divisible by
both 3 and 5. You can also write this as a single conditional filter, "Number % 3 == 0 && Number % 5 == 0", and
receive the same result.
You can use the || operator to OR multiple filters. For example, Y == `M` || Y == `N` matches when Y equals
M or N.
Returns
An aggregator that computes the number of values within an aggregation group that pass the provided filters.
Examples
The following table is used for all the examples:
In this example, agg.count_where returns the number of values of Number that are >= 20 and < 99 as grouped by X.
In this example, agg.count_where returns the number of values of Y that are M or N, as grouped by X.
In this example, agg.count_where returns the number of rows where Y equals 'M' and Number > 50 over the entire table (no grouping).
In this example, agg.count_where returns the number of rows where Number is between 50 and 100 (inclusive), as grouped by X and Y.