polars.internals.expr.list.ExprListNameSpace.diff#

ExprListNameSpace.diff(n: int = 1, null_behavior: NullBehavior = 'ignore') pli.Expr[source]#

Calculate the n-th discrete difference of every sublist.

Parameters:
n

Number of slots to shift.

null_behavior{‘ignore’, ‘drop’}

How to handle null values.

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]
]