pandas.Index.replace

pandas 3.1.1 · Index objects · method

Substitute values using a mapping or match pattern. Enable regex matching where needed.

Call syntax

Index.replace(to_replace=None, value=…, regex=False)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
to_replace Optional
Positional or keyword
Default None
str, regex, list, dict, Series, scalar, or None

Identify the values that should be replaced.

value Optional
Positional or keyword
scalar, dict, list, str, regex

Provide the value used for the documented operation, such as a replacement or a test point.

regex Optional
Positional or keyword
Default False
bool or same types as to_replace

Choose whether a supplied pattern is interpreted as a regular expression.

Returns

Index