polars.Expr.rolling_map
-
Compute a custom rolling window function.
Warning
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Changed in version 1.21.0: The
min_periodsparameter was renamedmin_samples.- Parameters:
-
- function
-
Custom aggregation function.
- window_size
-
The length of the window in number of elements.
- weights
-
An optional slice with the same length as the window that will be multiplied elementwise with the values in the window.
- min_samples
-
The number of values in the window that should be non-null before computing a result. If set to
None(default), it will be set equal towindow_size. - center
-
Set the labels at the center of the window.
Warning
Computing custom functions is extremely slow. Use specialized rolling functions such as
Expr.rolling_sum()if at all possible.Examples
>>> from numpy import nansum >>> df = pl.DataFrame({"a": [11.0, 2.0, 9.0, float("nan"), 8.0]}) >>> df.select(pl.col("a").rolling_map(nansum, window_size=3)) shape: (5, 1) ┌──────┐ │ a │ │ --- │ │ f64 │ ╞══════╡ │ null │ │ null │ │ 22.0 │ │ 11.0 │ │ 17.0 │ └──────┘
Expr.rolling_map(
function: Callable[[Series],
Any],
window_size: int,
weights: list_[float] | None = None,
*,
min_samples: int | None = None,
center: bool = False,
) → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.rolling_map.html