polars.Series.map_dict#

Series.map_dict(
mapping: dict[Any, Any],
*,
default: Any = None,
return_dtype: PolarsDataType | None = None,
) Self[source]#

Replace values in the Series using a remapping dictionary.

Deprecated since version 0.19.16: This method has been renamed to replace(). The default behavior has changed to keep any values not present in the mapping unchanged. Pass default=None to keep existing behavior.

Parameters:
mapping

Dictionary containing the before/after values to map.

default

Value to use when the remapping dict does not contain the lookup value. Use pl.first(), to keep the original value.

return_dtype

Set return dtype to override automatic return dtype determination.