pandas.Series.str.replace

pandas 3.1.1 · Series and accessors · method

Replace matching substrings inside each value. Set regex=True for regular-expression matching.

Call syntax

Series.str.replace(pat, repl=None, n=-1, case=None, flags=0, regex=False)

Run the example

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

Parameters

ParameterRequirementAccepted values and behavior
pat Required
Positional or keyword
str, compiled regex, or a dict

Specify the substring or regular expression to match.

repl Optional
Positional or keyword
Default None
str or callable
n Optional
Positional or keyword
Default -1
int

Choose how many entries or positions to use.

case Optional
Positional or keyword
Default None
bool

Choose whether uppercase and lowercase text are treated as distinct.

flags Optional
Positional or keyword
Default 0
int

Pass regular-expression modifiers such as re.IGNORECASE.

regex Optional
Positional or keyword
Default False
bool

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

Returns

Series or Index of object