polars.DataFrame.replace#

DataFrame.replace(column: str, new_col: Series) DF[source]#

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!
shape: (3, 2)
┌─────┬─────┐
│ foo ┆ bar │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 10  ┆ 4   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 20  ┆ 5   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 30  ┆ 6   │
└─────┴─────┘