Calculate the n-th discrete difference of every sublist.
Optional
n: numbernumber of slots to shift
Optional
nullBehavior: "ignore" | "drop"'ignore' | 'drop'
s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
s.lst.diff()
shape: (2,)
Series: 'a' [list]
[
[null, 1, ... 1]
[null, -8, -1]
]
>df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
>df.withColumn(
... pl.concatList(["a", "b"]).lst.eval(pl.first().rank()).alias("rank")
... )
shape: (3, 3)
┌─────┬─────┬────────────┐
│ a ┆ b ┆ rank │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ list [f32] │
╞═════╪═════╪════════════╡
│ 1 ┆ 4 ┆ [1.0, 2.0] │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 8 ┆ 5 ┆ [2.0, 1.0] │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 3 ┆ 2 ┆ [2.0, 1.0] │
└─────┴─────┴────────────┘
List functions for Series