polars otherwise

For expression.

Completes a when expression.

warning This command requires a plugin The polars otherwise 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.

Command Type

plugin

Signature

> polars otherwise {flags} (otherwise expression)

Parameters

  • otherwise expression: Expression to apply when no when predicate matches.

Input/output types:

input output
any polars_expression

Examples

Create a when conditions

> polars when ((polars col a) > 2) 4 | polars otherwise 5

Create a when conditions

> polars when ((polars col a) > 2) 4 | polars when ((polars col a) < 0) 6 | polars otherwise 0

Create a new column for the dataframe

> [[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 │
╰───┴───┴───┴───┴────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.