polars with-column for [dataframe or lazyframe](/commands/categories/dataframe or lazyframe.md)

Adds a series to the dataframe.

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:

inputoutput
anyany

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
╰───┴───┴───┴───┴───╯