maxframe.liteframe.LiteFrame.str.replace#
- LiteFrame.str.replace(pat: str | re.Pattern | dict, repl: str | Callable | None = None, n: int = -1, case: bool | None = None, flags: int = 0, regex: bool = False)#
Replace each occurrence of pattern/regex in the Series/Index.
Equivalent to
str.replace()orre.sub(), depending on the regex value.- Parameters:
pat (str, compiled regex, or a dict) – String can be a character sequence or regular expression. Dictionary contains <key : value> pairs of strings to be replaced along with the updated value.
repl (str or callable) – Replacement string or a callable. The callable is passed the regex match object and must return a replacement string to be used. Must have a value of None if pat is a dict See
re.sub().n (int, default -1 (all)) – Number of replacements to make from start.
case (bool, 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 (no flags)) – Regex module flags, e.g. re.IGNORECASE. Cannot be set if pat is a compiled regex.
regex (bool, 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:
- Raises:
if regex is False and repl is a callable or pat is a compiled regex * if pat is a compiled regex and case or flags is set * if pat is a dictionary and repl is not None.
See also
LiteFrame.str.replaceMethod to replace occurrences of a substring with another substring.
LiteFrame.str.extractExtract substrings using a regular expression.
LiteFrame.str.findallFind all occurrences of a pattern or regex in each string.
LiteFrame.str.splitSplit each string by a specified delimiter or pattern.
Notes
When pat is a compiled regex, all flags should be included in the compiled regex. Use of case, flags, or regex=False with a compiled regex will raise an error.