cum_prod
cum_prod
calculates a cumulative product in an update_by
table operation.
Syntax
cum_prod(cols: list[str]) -> UpdateByOperation
Parameters
Parameter | Type | Description |
---|---|---|
cols | list[str] | The column(s) to be operated on. These can include expressions to rename the output columns (e.g., |
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_prod
operation. No grouping columns are given, so the cumulative product is calculated across all rows of the table.
from deephaven.updateby import cum_prod
from deephaven import empty_table
source = empty_table(10).update(["Letter = (i % 2 == 0) ? `A` : `B`", "X = i + 1"])
result = source.update_by(ops=cum_prod(cols=["ProdX = X"]), by=[])
- result
- source
The following example builds on the previous by specifying Letter
as a grouping column. Thus, the cumulative product in the result
table is calculated on a per-letter basis.
from deephaven.updateby import cum_prod
from deephaven import empty_table
source = empty_table(10).update(["Letter = (i % 2 == 0) ? `A` : `B`", "X = i + 1"])
result = source.update_by(ops=cum_prod(cols=["CumX = X"]), by=["Letter"])
- result
- source
The following example builds on the previous by calculating the cumulative product of two columns using the same UpdateByOperation.
from deephaven.updateby import cum_prod
from deephaven import empty_table
source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = i + 1", "Y = randomInt(1, 7)"]
)
result = source.update_by(ops=cum_prod(cols=["ProdX = X", "ProdY = Y"]), by=["Letter"])
- result
- source
The following example builds on the previous by specifying two grouping columns: Letter
and Truth
. Thus, groups consist of unique combinations of letter in Letter
and boolean in Truth
.
from deephaven.updateby import cum_prod
from deephaven import empty_table
source = empty_table(10).update(
[
"Letter = (i % 2 == 0) ? `A` : `B`",
"Truth = randomBool()",
"X = i + 1",
"Y = randomInt(1, 7)",
]
)
result = source.update_by(
ops=cum_prod(cols=["ProdX = X", "ProdY = Y"]), by=["Letter", "Truth"]
)
- result
- source