polars with-column
for [dataframe or lazyframe](/commands/categories/dataframe or lazyframe.md)
Adds a series to the dataframe.
This command requires a plugin
The polars with-column
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 with-column {flags} ...rest
Flags
--name, -n {string}
: new column name
Parameters
...rest
: series to be added or expressions used to define the new columns
Input/output types:
input | output |
---|---|
any | any |
Examples
Adds a series to the dataframe
> [[a b]; [1 2] [3 4]]
| polars into-df
| polars with-column ([5 6] | polars into-df) --name c
╭───┬───┬───┬───╮
│ # │ a │ b │ c │
├───┼───┼───┼───┤
│ 0 │ 1 │ 2 │ 5 │
│ 1 │ 3 │ 4 │ 6 │
╰───┴───┴───┴───╯
Adds a series to the dataframe
> [[a b]; [1 2] [3 4]]
| polars into-lazy
| polars with-column [
((polars col a) * 2 | polars as "c")
((polars col a) * 3 | polars as "d")
]
| polars collect
╭───┬───┬───┬───┬───╮
│ # │ a │ b │ c │ d │
├───┼───┼───┼───┼───┤
│ 0 │ 1 │ 2 │ 2 │ 3 │
│ 1 │ 3 │ 4 │ 6 │ 9 │
╰───┴───┴───┴───┴───╯