polars.Expr.diff¶
- Expr.diff(n: int = 1, null_behavior: str = 'ignore') polars.internals.expr.Expr ¶
Calculate the n-th discrete difference.
- Parameters
- n
number of slots to shift
- null_behavior
{‘ignore’, ‘drop’}
Examples
>>> df = pl.DataFrame( ... { ... "a": [20, 10, 30], ... } ... ) >>> df.select(pl.col("a").diff()) shape: (3, 1) ┌──────┐ │ a │ │ --- │ │ i64 │ ╞══════╡ │ null │ ├╌╌╌╌╌╌┤ │ -10 │ ├╌╌╌╌╌╌┤ │ 20 │ └──────┘