bigframes.pandas.api.typing.StringMethods.replace#
- StringMethods.replace(pat: str | Pattern, repl: str, *, case: bool | None = None, flags: int = 0, regex: bool = False) T[source]#
Replace each occurrence of pattern/regex in the Series/Index.
Equivalent to
str.replace()orre.sub(), depending on the regex value.Examples:
>>> import bigframes.pandas as bpd
When pat is a string and regex is True, the given pat is compiled as a regex. When repl is a string, it replaces matching regex patterns as with re.sub(). NaN value(s) in the Series are left as is:
>>> s = bpd.Series(['foo', 'fuz', pd.NA]) >>> s.str.replace('f.', 'ba', regex=True) 0 bao 1 baz 2 <NA> dtype: string
When pat is a string and regex is False, every pat is replaced with repl as with str.replace():
>>> s = bpd.Series(['f.o', 'fuz', pd.NA]) >>> s.str.replace('f.', 'ba', regex=False) 0 bao 1 fuz 2 <NA> dtype: string
- Parameters:
pat (str, re.Pattern) – String can be a character sequence or regular expression.
repl (str) – Replacement string.
case (default None) –
Determines if replace is case sensitive:
If True, case sensitive (the default if pat is a string)
Set to False for case insensitive
Cannot be set if pat is a compiled regex.
flags (int, default 0) – Regex module flags, e.g. re.IGNORECASE. Cannot be set if pat is a compiled regex.
(bool (regex) –
default False): Determines if the passed-in pattern is a regular expression:
If True, assumes the passed-in pattern is a regular expression.
If False, treats the pattern as a literal string
- Cannot be set to False if pat is a compiled regex or repl is
a callable.
- Returns:
- A copy of the object with all matching occurrences
of pat replaced by repl.
- Return type: