polars.Series.cumulative_eval#

Series.cumulative_eval(
expr: Expr,
*,
min_periods: int = 1,
parallel: bool = False,
) Series[source]#

在每次迭代增加1个槽的滑动窗口上运行表达式。

警告

此功能被视为不稳定。它可能会在任何时候更改,而不被视为破坏性更改。

Parameters:
expr

要评估的表达式

min_periods

在表达式被评估之前,窗口中应该存在的有效值的数量。有效值 = length - null_count

parallel

并行运行。不要在已经具有大量并行化的分组或其他操作中执行此操作。

警告

这可能会非常慢,因为它可能具有O(n^2)的复杂度。不要在对所有元素进行操作的场景中使用此方法。

示例

>>> s = pl.Series("values", [1, 2, 3, 4, 5])
>>> s.cumulative_eval(pl.element().first() - pl.element().last() ** 2)
shape: (5,)
Series: 'values' [i64]
[
    0
    -3
    -8
    -15
    -24
]