W3cubDocs

/Nushell

dfr when for expression

Creates and modifies a when expression.

Signature

> dfr when {flags} (when expression) (then expression)

Parameters

  • when expression: when expression used for matching
  • then expression: expression that will be applied when predicate is true

Input/output types:

input output
any any

Examples

Create a when conditions

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

Create a when conditions

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

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_when.html