polars dummies
for dataframe
Creates a new dataframe with dummy variables.
This command requires a plugin
The polars dummies
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.
Signature
> polars dummies {flags}
Flags
--drop-first, -d
: Drop first row
Input/output types:
input | output |
---|---|
any | any |
Examples
Create new dataframe with dummy variables from a dataframe
> [[a b]; [1 2] [3 4]] | polars into-df | polars dummies
╭───┬─────┬─────┬─────┬─────╮
│ # │ a_1 │ a_3 │ b_2 │ b_4 │
├───┼─────┼─────┼─────┼─────┤
│ 0 │ 1 │ 0 │ 1 │ 0 │
│ 1 │ 0 │ 1 │ 0 │ 1 │
╰───┴─────┴─────┴─────┴─────╯
Create new dataframe with dummy variables from a series
> [1 2 2 3 3] | polars into-df | polars dummies
╭───┬─────┬─────┬─────╮
│ # │ 0_1 │ 0_2 │ 0_3 │
├───┼─────┼─────┼─────┤
│ 0 │ 1 │ 0 │ 0 │
│ 1 │ 0 │ 1 │ 0 │
│ 2 │ 0 │ 1 │ 0 │
│ 3 │ 0 │ 0 │ 1 │
│ 4 │ 0 │ 0 │ 1 │
╰───┴─────┴─────┴─────╯