polars math
for dataframe
Collection of math functions to be applied on one or more column expressions
This command requires a plugin
The polars math
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 math {flags} (type) ...rest
Parameters
type
: Function name. See extra description for full list of accepted values...rest
: Extra arguments required by some functions
Input/output types:
input | output |
---|---|
expression | expression |
Examples
Apply function to column expression
> [[a]; [0] [-1] [2] [-3] [4]]
| polars into-df
| polars select [
(polars col a | polars math abs | polars as a_abs)
(polars col a | polars math sign | polars as a_sign)
(polars col a | polars math exp | polars as a_exp)]
| polars collect
╭───┬───────┬────────┬───────╮
│ # │ a_abs │ a_sign │ a_exp │
├───┼───────┼────────┼───────┤
│ 0 │ 0 │ 0 │ 1.00 │
│ 1 │ 1 │ -1 │ 0.37 │
│ 2 │ 2 │ 1 │ 7.39 │
│ 3 │ 3 │ -1 │ 0.05 │
│ 4 │ 4 │ 1 │ 54.60 │
╰───┴───────┴────────┴───────╯
Specify arguments for select functions. See description for more information.
> [[a]; [0] [1] [2] [4] [8] [16]]
| polars into-df
| polars select [
(polars col a | polars math log 2 | polars as a_base2)]
| polars collect
╭───┬─────────╮
│ # │ a_base2 │
├───┼─────────┤
│ 0 │ -inf │
│ 1 │ 0.00 │
│ 2 │ 1.00 │
│ 3 │ 2.00 │
│ 4 │ 3.00 │
│ 5 │ 4.00 │
╰───┴─────────╯
Specify arguments for select functions. See description for more information.
> [[a b]; [0 0] [1 1] [2 2] [3 3] [4 4] [5 5]]
| polars into-df
| polars select [
(polars col a | polars math dot (polars col b) | polars as ab)]
| polars collect
╭───┬───────╮
│ # │ ab │
├───┼───────┤
│ 0 │ 55.00 │
╰───┴───────╯
Notes
This is an incomplete implementation of the available functions listed here: https://docs.pola.rs/api/python/stable/reference/expressions/computation.html.
The following functions are currently available:
- abs
- cos
- dot <expression>
- exp
- log <base; default e>
- log1p
- sign
- sin
- sqrt