This is a temporary archive of the Deephaven documentation. For latest documentation please see https://deephaven.io/.
Skip to main content
Version: Python

cum_count_where

cum_count_where performs a cumulative count of values that pass a set of filters in an update_by table operation.

Syntax

cum_count_where(col: str, filters: Union[str, Filter, List[str], List[Filter]]) -> UpdateByOperation

Parameters

ParameterTypeDescription
colstr

The name of the column that will contain the count of values that pass the filters.

filtersUnion[str, Filter, Sequence[str], Sequence[Filter]]

Formulas for filtering as a list of Strings.

Any filter is permitted, as long as it is not refreshing and does not use row position/key variables or arrays.

tip

Providing multiple filter strings in the filters parameter results in an AND operation being applied to the filters. For example, "Number % 3 == 0", "Number % 5 == 0" returns 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 UpdateByOperation to be used in an update_by table operation.

Examples

The following example performs an update_by on the source table using the cum_count_where operation and counting rows where Y is >= 20 and < 99. No grouping columns are given, so the cumulative count is calculated for all rows in the table.

from deephaven.updateby import cum_count_where
from deephaven import empty_table

source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = i % 3", "Y = randomInt(0, 100)"]
)

result = source.update_by(
ops=cum_count_where(col="count", filters=["Y >= 20", "Y < 99"])
)

The following example builds off the previous by specifying Letter as the grouping column. Thus, the cumulative count includes rows where Y is >= 20 and < 99 and is calculated for each unique letter.

from deephaven.updateby import cum_count_where
from deephaven import empty_table

source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = i % 3", "Y = randomInt(0, 100)"]
)

result = source.update_by(
ops=cum_count_where(col="count", filters="Y >= 20 && Y < 99"), by="Letter"
)

In the next example, cum_count_where returns the number of rows where Letter equals 'A' and Y > 50 over the entire table (without grouping).

from deephaven.updateby import cum_count_where
from deephaven import empty_table

source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = i % 3", "Y = randomInt(0, 100)"]
)

result = source.update_by(
ops=cum_count_where(col="count", filters=["Letter == `A`", "Y > 50"])
)

This example returns the number of rows where Y is between 50 and 100 (inclusive), as grouped by Letter and X.

from deephaven.updateby import cum_count_where
from deephaven import empty_table

source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = i % 3", "Y = randomInt(0, 100)"]
)

result = source.update_by(
ops=cum_count_where(col="count", filters=["Y >= 50", "Y <= 100"]),
by=["Letter", "X"],
)