Spec-Zone.ru › Polars

polars.Expr.cumulative_eval

Expr.cumulative_eval(
    expr: Expr,
    *,
    min_samples: int = 1,
) → Expr

Run an expression over a sliding window that increases 1 slot every iteration.

engine:In MemoryPartially Streaming

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_periods parameter was renamed min_samples.

Parameters:
expr

Expression to evaluate

min_samples

Number of valid values there should be in the window before the expression is evaluated. valid values = length - null_count

Warning

This can be really slow as it can have O(n^2) complexity. Don’t use this for operations that visit all elements.

Examples

>>> df = pl.DataFrame({"values": [1, 2, 3, 4, 5]})
>>> df.select(
...     [
...         pl.col("values").cumulative_eval(
...             pl.element().first() - pl.element().last() ** 2
...         )
...     ]
... )
shape: (5, 1)
┌────────┐
│ values │
│ ---    │
│ i64    │
╞════════╡
│ 0      │
│ -3     │
│ -8     │
│ -15    │
│ -24    │
└────────┘

© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.cumulative_eval.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API