diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index d37ce53d4776..8ee1e3b17b82 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -5719,6 +5719,27 @@ def rolling( │ 2020-01-03 19:45:32 ┆ 11 ┆ 2 ┆ 9 │ │ 2020-01-08 23:16:43 ┆ 1 ┆ 1 ┆ 1 │ └─────────────────────┴───────┴───────┴───────┘ + + If you use an index count in `period` or `offset`, then it's based on the + values in `index_column`: + + >>> df = pl.DataFrame({"int": [0, 4, 5, 6, 8], "value": [1, 4, 2, 4, 1]}) + >>> df.rolling("int", period="3i").agg(pl.col("int").alias("aggregated")) + shape: (5, 2) + ┌─────┬────────────┐ + │ int ┆ aggregated │ + │ --- ┆ --- │ + │ i64 ┆ list[i64] │ + ╞═════╪════════════╡ + │ 0 ┆ [0] │ + │ 4 ┆ [4] │ + │ 5 ┆ [4, 5] │ + │ 6 ┆ [4, 5, 6] │ + │ 8 ┆ [6, 8] │ + └─────┴────────────┘ + + If you want the index count to be based on row number, then you may want to + combine `rolling` with :meth:`.with_row_index`. """ period = deprecate_saturating(period) offset = deprecate_saturating(offset)