polars when для выражений
Создаёт и изменяет выражение when.
Сигнатура
> polars when {flags} (when expression) (then expression)
Параметры
-
when expression: Выражение when, используемое для сопоставления. -
then expression: Выражение, которое будет применено, если предикат имеет значение true.
Типы входных и выходных данных:
| вход | выход |
|---|---|
| ничего | polars_expression |
| polars_expression | polars_expression |
| любое значение | polars_expression |
Примеры
Создание условий when
> polars when ((polars col a) > 2) 4
Создание условий when
> polars when ((polars col a) > 2) 4 | polars when ((polars col a) < 0) 6
Создание нового столбца для фрейма данных
> [[a b]; [6 2] [1 4] [4 1]]
| polars into-lazy
| polars with-column (
polars when ((polars col a) > 2) 4 | polars otherwise 5 | polars as c
)
| polars with-column (
polars when ((polars col a) > 5) 10 | polars when ((polars col a) < 2) 6 | polars otherwise 0 | polars as d
)
| polars collect
╭───┬───┬───┬───┬────╮
│ # │ a │ b │ c │ d │
├───┼───┼───┼───┼────┤
│ 0 │ 6 │ 2 │ 4 │ 10 │
│ 1 │ 1 │ 4 │ 5 │ 6 │
│ 2 │ 4 │ 1 │ 4 │ 0 │
╰───┴───┴───┴───┴────╯
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_when.html