W3cubDocs

/Nushell

dfr otherwise for expression

completes a when expression.

Signature

> dfr otherwise {flags} (otherwise expression)

Parameters

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

Input/output types:

input output
any any

Examples

Create a when conditions

>dfr when ((dfr cola) >2) 4|dfr otherwise5

Create a when conditions

>dfr when ((dfr cola) >2) 4|dfr when ((dfr cola) <0) 6|dfr otherwise0

Create a new column for the dataframe

> [[ab]; [62] [14] [41]]
|dfr into-lazy
|dfr with-column (
dfr when ((dfr cola) >2) 4|dfr otherwise5|dfr asc
     )
|dfr with-column (
dfr when ((dfr cola) >5) 10|dfr when ((dfr cola) <2) 6|dfr otherwise0|dfr asd
     )
|dfr collect
╭───┬───┬───┬───┬────╮
# │ a │ b │ c │ d  │
├───┼───┼───┼───┼────┤
062410
11456
24140
╰───┴───┴───┴───┴────╯

Tips: Dataframe commands were not shipped in the official binaries by default, you have to build it with --features=dataframe flag

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