Return the cumulative count of the non-null values in the column
Description
Return the cumulative count of the non-null values in the column
Usage
<Expr>$cumulative_eval(expr, ..., min_periods = 1, parallel = FALSE)
Arguments
expr
|
Expression to evaluate. |
…
|
These dots are for future extensions and must be empty. |
min_periods
|
Number of valid values (i.e. length - null_count ) there
should be in the window before the expression is evaluated.
|
parallel
|
Run in parallel. Don’t do this in a group by or another operation that already has much parallelization. |
Details
This can be really slow as it can have O(n^2)
complexity.
Don’t use this for operations that visit all elements.
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(values = 1:5)
df$with_columns(
pl$col("values")$cumulative_eval(
pl$element()$first() - pl$element()$last()**2
)
)
#> shape: (5, 1)
#> ┌────────┐
#> │ values │
#> │ --- │
#> │ f64 │
#> ╞════════╡
#> │ 0.0 │
#> │ -3.0 │
#> │ -8.0 │
#> │ -15.0 │
#> │ -24.0 │
#> └────────┘