Я попробовал это с помощью следующего фрагмента кода:
Код: Выделить всё
import polars as pl
df = pl.DataFrame(
{
"A": [1, 2, 9, 2, 13],
}
)
df.select(
pl.col("A").rolling_map(lambda s: s, 3),
)
Код: Выделить всё
┌──────┐
│ A │
│ --- │
│ i64 │
╞══════╡
│ null │
│ null │
│ 1 │
│ 2 │
│ 9 │
└──────┘
Код: Выделить всё
shape: (5, 1)
┌─────────────────┐
│ A │
│ --- │
│ list[i64] │
╞═════════════════╡
│ [null, null, 1] │
│ [null, 1, 2] │
│ [1, 2, 9] │
│ [2, 9, 2] │
│ [9, 2, 13] │
└─────────────────┘
Подробнее здесь: https://stackoverflow.com/questions/703 ... rolling-wi