Skip to main content
Version: 1.3.0

Expr.diff

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
n

The 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
22
31
41
-1-5
-2-1
-3-1
-4-1
-5-1
│ null ┆ null │
└──────┴──────┘