Spec-Zone.ru › Nushell

polars math for dataframe

Collection of math functions to be applied on one or more column expressions

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
polars_expression polars_expression
polars_selector polars_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.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_math.html

Spec-Zone.ru

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