Loading...

verticapy.sql.functions.conditional_true_event#

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

Assigns an event window number to each row, starting from 0, and increments the number by 1 when the result of the boolean argument expression evaluates true.

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["ctrue_event"] = vpf.conditional_true_event(df["y"] > 0)._over(order_by = [df["x"]])
display(df)
123
x
Integer
100%
...
123
y
Numeric(21)
100%
123
ctrue_event
Integer
100%
11...11.41
22...-2.51
33...3.52
44...-4.22
55...2.03

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.