polars.DataFrame.replace

DataFrame.replace(column: str, new_col: polars.internals.series.Series) None

Replace a column by a new Series.

Parameters
column

Column to replace.

new_col

New column to insert.

Examples

>>> df = pl.DataFrame({"foo": [1, 2, 3], "bar": [4, 5, 6]})
>>> s = pl.Series([10, 20, 30])
>>> df.replace("foo", s)  # works in-place!
>>> df
shape: (3, 2)
┌─────┬─────┐
│ foo ┆ bar │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 10  ┆ 4   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 20  ┆ 5   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 30  ┆ 6   │
└─────┴─────┘