polars.internals.expr.ExprListNameSpace.diff

ExprListNameSpace.diff(n: int = 1, null_behavior: str = 'ignore') polars.internals.expr.Expr

Calculate the n-th discrete difference of every sublist.

Parameters
n

number of slots to shift

null_behavior

{‘ignore’, ‘drop’}

Examples

>>> s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
>>> s.arr.diff()
shape: (2,)
Series: 'a' [list]
[
    [null, 1, ... 1]
    [null, -8, -1]
]