🍾 Xarray is now 10 years old! πŸŽ‰

xarray.DataArray.str.contains

xarray.DataArray.str.contains#

DataArray.str.contains(pat, case=None, flags=0, regex=True)[source]#

Test if pattern or regex is contained within each string of the array.

Return boolean array based on whether a given pattern or regex is contained within a string of the array.

The pattern pat can either be a single str or re.Pattern or array-like of str or re.Pattern. If array-like, it is broadcast against the array and applied elementwise.

Parameters:
  • pat (str or re.Pattern or array-like of str or re.Pattern) – Character sequence, a string containing a regular expression, or a compiled regular expression object. If array-like, it is broadcast.

  • case (bool, default: True) – If True, case sensitive. Cannot be set if pat is a compiled regex. Equivalent to setting the re.IGNORECASE flag.

  • flags (int, default: 0) – Flags to pass through to the re module, e.g. re.IGNORECASE. see compilation-flags. 0 means no flags. Flags can be combined with the bitwise or operator |. Cannot be set if pat is a compiled regex.

  • regex (bool, default: True) – If True, assumes the pat is a regular expression. If False, treats the pat as a literal string. Cannot be set to False if pat is a compiled regex.

Returns:

contains (array of bool) – An array of boolean values indicating whether the given pattern is contained within the string of each element of the array.