polars over
for lazyframe
Compute expressions over a window group defined by partition expressions.
This command requires a plugin
The polars over
command resides in the polars
plugin. To use this command, you must install and register nu_plugin_polars
. See the Plugins chapter in the book for more information.
Signature
> polars over {flags} ...rest
Parameters
...rest
: Expression(s) that define the partition window
Input/output types:
input | output |
---|---|
any | any |
Examples
Compute expression over an aggregation window
> [[a b]; [x 2] [x 4] [y 6] [y 4]]
| polars into-lazy
| polars select a (polars col b | polars cumulative sum | polars over a | polars as cum_b)
| polars collect
╭───┬───┬───────╮
│ # │ a │ cum_b │
├───┼───┼───────┤
│ 0 │ x │ 2 │
│ 1 │ x │ 6 │
│ 2 │ y │ 6 │
│ 3 │ y │ 10 │
╰───┴───┴───────╯
Compute expression over an aggregation window where partitions are defined by expressions
> [[a b]; [x 2] [X 4] [Y 6] [y 4]]
| polars into-lazy
| polars select a (polars col b | polars cumulative sum | polars over (polars col a | polars lowercase) | polars as cum_b)
| polars collect
╭───┬───┬───────╮
│ # │ a │ cum_b │
├───┼───┼───────┤
│ 0 │ x │ 2 │
│ 1 │ X │ 6 │
│ 2 │ Y │ 6 │
│ 3 │ y │ 10 │
╰───┴───┴───────╯