Loading...

verticapy.sql.functions.conditional_change_event#

verticapy.sql.functions.conditional_change_event(expr: str | list[str] | StringSQL | list[StringSQL]) StringSQL#

Assigns an event window number to each row, starting from 0, and increments by 1 when the result of evaluating the argument expression on the current row differs from that on the previous row.

Parameters#

expr: SQLExpression

Expression.

Returns#

StringSQL

SQL string.

Examples#

First, let’s import the vDataFrame in order to create a dummy dataset.

from verticapy import vDataFrame

Now, let’s import the VerticaPy SQL functions.

import verticapy.sql.functions as vpf

We can now build a dummy dataset.

df = vDataFrame(
    {
        "x": [1, 2, 3, 4, 5, 6],
        "y": [11.4, -2.5, 3.5, -4.2, 2, 3],
    },
)

Now, let’s go ahead and apply the function.

df["cchange_event"] = vpf.conditional_change_event(df["y"] > 0)._over(order_by = [df["x"]])
display(df)
123
x
Integer
100%
...
123
y
Numeric(21)
100%
123
cchange_event
Integer
100%
11...11.40
22...-2.51
33...3.52
44...-4.23
55...2.04

Note

It’s crucial to utilize VerticaPy SQL functions in coding, as they can be updated over time with new syntax. While SQL functions typically remain stable, they may vary across platforms or versions. VerticaPy effectively manages these changes, a task not achievable with pure SQL.

See also

vDataFrame.eval() : Evaluates the expression.