pandas.DataFrame.replace
pandas 3.1.1 · DataFrame · method
Substitute values using a mapping or match pattern. Enable regex matching where needed.
Call syntax
DataFrame.replace(to_replace=None, value=…, *, inplace=False, regex=False)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
to_replace |
Optional Positional or keyword Default None |
str, regex, list, dict, Series, int, float, 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. |
inplace |
Optional Keyword only Default False |
bool Choose whether to change the existing object. Where supported, an in-place call typically returns None. |
regex |
Optional Keyword only Default False |
bool or same types as to_replace Choose whether a supplied pattern is interpreted as a regular expression. |
Returns
Series/DataFrame