Expr.diff
methodView source ↗
def diff(n: int = 1) -> Expr
Categories: numeric
Compute the difference between an element value and the element value of the specified relative row.
It supports numberic and datetime types.
Parameters
parameter
nThe relative row to compute the difference with. Defaults to 1 (previous). Use a negative number to get a next row.
Examples
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
>>> tf.select(td.col("i"), td.col("i").diff().diff().alias("diff"))
>>>
┌──────┬──────┐
│ i ┆ diff │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞══════╪══════╡
│ 1 ┆ null │
│ 0 ┆ -1 │
│ 2 ┆ 2 │
│ 3 ┆ 1 │
│ 4 ┆ 1 │
│ -1 ┆ -5 │
│ -2 ┆ -1 │
│ -3 ┆ -1 │
│ -4 ┆ -1 │
│ -5 ┆ -1 │
│ null ┆ null │
└──────┴──────┘