snowflake.snowpark.DataFrameAnalyticsFunctions.compute_lag¶
- DataFrameAnalyticsFunctions.compute_lag(cols: ~typing.List[~typing.Union[str, ~snowflake.snowpark.column.Column]], lags: ~typing.List[int], order_by: ~typing.List[str], group_by: ~typing.List[str], col_formatter: ~typing.Callable[[str, str, int], str] = <function DataFrameAnalyticsFunctions._default_col_formatter>) DataFrame[source]¶
Creates lag columns to the specified columns of the DataFrame by grouping and ordering criteria.
- Parameters:
cols – List of column names or Column objects to calculate lag features.
lags – List of positive integers specifying periods to lag by.
order_by – A list of column names that specify the order in which rows are processed.
group_by – A list of column names on which the DataFrame is partitioned for separate window calculations.
col_formatter – An optional function for formatting output column names, defaulting to the format ‘<input_col>LAG<lag>’. This function takes three arguments: ‘input_col’ (str) for the column name, ‘operation’ (str) for the applied operation, and ‘value’ (int) for lag value, and returns a formatted string for the column name.
- Returns:
A Snowflake DataFrame with additional columns corresponding to each specified lag period.
Example