xarray.DataArray.str.replace

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

Replace occurrences of pattern/regex in the array with some string.

Parameters
  • pat (str or re.Pattern) – String can be a character sequence or regular expression.

  • 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. See re.sub().

  • n (int, default: -1) – Number of replacements to make from start. Use -1 to replace all.

  • case (bool, default: None) –

    • 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) –

    • re module flags, e.g. re.IGNORECASE. Use 0 for no flags.

    • Cannot be set if pat is a compiled regex

  • regex (bool, default: True) –

    • 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

replaced – A copy of the object with all matching occurrences of pat replaced by repl.

Return type

same type as values