polars.DataFrame.replace#

DataFrame.replace(column: str, new_column: Series) Self[source]#

Replace a column by a new Series.

Deprecated since version 0.19.0: Use with_columns() instead, e.g. df = df.with_columns(new_column.alias(column_name)).

Parameters:
column

Column to replace.

new_column

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   │
└─────┴─────┘