verticapy.sql.functions.lead#
- verticapy.sql.functions.lead(expr: str | list[str] | StringSQL | list[StringSQL], offset: int = 1) StringSQL #
Returns values from the row after the current row within a window, letting you access more than one row in a table at the same time.
Parameters#
- expr: SQLExpression
Expression.
- offset: int
Indicates how great is the lead.
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], "y": [11.4, -2.5, 3.5, -4.2], }, )
Now, let’s go ahead and apply the function.
df["lead"] = vpf.lead(df["y"], 1)._over(order_by = [df["x"]]) display(df)
123xInteger100%... 123yNumeric(5)100%123leadNumeric(5)75%1 1 ... 11.4 -2.5 2 2 ... -2.5 3.5 3 3 ... 3.5 -4.2 4 4 ... -4.2 [null] 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.