polars dummies for dataframe
Creates a new dataframe with dummy variables.
Signature
> polars dummies {flags}
Flags
-
--drop-first, -d: Drop first row. -
--drop-nulls, -n: Drop nulls. -
--separator, -s: Optional separator.
Input/output types:
| input | output |
|---|---|
| polars_dataframe | polars_dataframe |
| polars_lazyframe | polars_lazyframe |
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 │ ╰───┴─────┴─────┴─────╯
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_dummies.html