# xarray.core.accessor_str.StringAccessor

### *class* xarray.core.accessor_str.StringAccessor(obj)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L144-L2912)

Vectorized string functions for string-like arrays.

Similar to pandas, fields can be accessed through the .str attribute
for applicable DataArrays.

```pycon
>>> da = xr.DataArray(["some", "text", "in", "an", "array"])
>>> da.str.len()
<xarray.DataArray (dim_0: 5)> Size: 40B
array([4, 4, 2, 2, 5])
Dimensions without coordinates: dim_0
```

It also implements `+`, `*`, and `%`, which operate as elementwise
versions of the corresponding `str` methods. These will automatically
broadcast for array-like inputs.

```pycon
>>> da1 = xr.DataArray(["first", "second", "third"], dims=["X"])
>>> da2 = xr.DataArray([1, 2, 3], dims=["Y"])
>>> da1.str + da2
<xarray.DataArray (X: 3, Y: 3)> Size: 252B
array([['first1', 'first2', 'first3'],
       ['second1', 'second2', 'second3'],
       ['third1', 'third2', 'third3']], dtype='<U7')
Dimensions without coordinates: X, Y
```

```pycon
>>> da1 = xr.DataArray(["a", "b", "c", "d"], dims=["X"])
>>> reps = xr.DataArray([3, 4], dims=["Y"])
>>> da1.str * reps
<xarray.DataArray (X: 4, Y: 2)> Size: 128B
array([['aaa', 'aaaa'],
       ['bbb', 'bbbb'],
       ['ccc', 'cccc'],
       ['ddd', 'dddd']], dtype='<U4')
Dimensions without coordinates: X, Y
```

```pycon
>>> da1 = xr.DataArray(["%s_%s", "%s-%s", "%s|%s"], dims=["X"])
>>> da2 = xr.DataArray([1, 2], dims=["Y"])
>>> da3 = xr.DataArray([0.1, 0.2], dims=["Z"])
>>> da1.str % (da2, da3)
<xarray.DataArray (X: 3, Y: 2, Z: 2)> Size: 240B
array([[['1_0.1', '1_0.2'],
        ['2_0.1', '2_0.2']],

       [['1-0.1', '1-0.2'],
        ['2-0.1', '2-0.2']],

       [['1|0.1', '1|0.2'],
        ['2|0.1', '2|0.2']]], dtype='<U5')
Dimensions without coordinates: X, Y, Z
```

#### NOTE
When using `%` formatting with a dict, the values are always used as a
single value, they are not applied elementwise.

```pycon
>>> da1 = xr.DataArray(["%(a)s"], dims=["X"])
>>> da2 = xr.DataArray([1, 2, 3], dims=["Y"])
>>> da1 % {"a": da2}
<xarray.DataArray (X: 1)> Size: 8B
array(['<xarray.DataArray (Y: 3)> Size: 24B\narray([1, 2, 3])\nDimensions without coordinates: Y'],
      dtype=object)
Dimensions without coordinates: X
```

#### \_\_init_\_(obj)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L209-L210)

### Methods

| [`__init__`](#xarray.core.accessor_str.StringAccessor.__init__)(obj)                                                                                   |                                                                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [`capitalize`](xarray.core.accessor_str.StringAccessor.capitalize.html.md#xarray.core.accessor_str.StringAccessor.capitalize)()                                 | Convert strings in the array to be capitalized.                                                                           |
| [`casefold`](xarray.core.accessor_str.StringAccessor.casefold.html.md#xarray.core.accessor_str.StringAccessor.casefold)()                                     | Convert strings in the array to be casefolded.                                                                            |
| [`cat`](xarray.core.accessor_str.StringAccessor.cat.html.md#xarray.core.accessor_str.StringAccessor.cat)(\*others[, sep])                                | Concatenate strings elementwise in the DataArray with other strings.                                                      |
| [`center`](xarray.core.accessor_str.StringAccessor.center.html.md#xarray.core.accessor_str.StringAccessor.center)(width[, fillchar])                        | Pad left and right side of each string in the array.                                                                      |
| [`contains`](xarray.core.accessor_str.StringAccessor.contains.html.md#xarray.core.accessor_str.StringAccessor.contains)(pat[, case, flags, regex])            | Test if pattern or regex is contained within each string of the array.                                                    |
| [`count`](xarray.core.accessor_str.StringAccessor.count.html.md#xarray.core.accessor_str.StringAccessor.count)(pat[, flags, case])                         | Count occurrences of pattern in each string of the array.                                                                 |
| [`decode`](xarray.core.accessor_str.StringAccessor.decode.html.md#xarray.core.accessor_str.StringAccessor.decode)(encoding[, errors])                       | Decode character string in the array using indicated encoding.                                                            |
| [`encode`](xarray.core.accessor_str.StringAccessor.encode.html.md#xarray.core.accessor_str.StringAccessor.encode)(encoding[, errors])                       | Encode character string in the array using indicated encoding.                                                            |
| [`endswith`](xarray.core.accessor_str.StringAccessor.endswith.html.md#xarray.core.accessor_str.StringAccessor.endswith)(pat)                                  | Test if the end of each string in the array matches a pattern.                                                            |
| [`extract`](xarray.core.accessor_str.StringAccessor.extract.html.md#xarray.core.accessor_str.StringAccessor.extract)(pat, dim[, case, flags])                | Extract the first match of capture groups in the regex pat as a new dimension in a DataArray.                             |
| [`extractall`](xarray.core.accessor_str.StringAccessor.extractall.html.md#xarray.core.accessor_str.StringAccessor.extractall)(pat, group_dim, match_dim[, ...]) | Extract all matches of capture groups in the regex pat as new dimensions in a DataArray.                                  |
| [`find`](xarray.core.accessor_str.StringAccessor.find.html.md#xarray.core.accessor_str.StringAccessor.find)(sub[, start, end, side])                      | Return lowest or highest indexes in each strings in the array where the substring is fully contained between [start:end]. |
| [`findall`](xarray.core.accessor_str.StringAccessor.findall.html.md#xarray.core.accessor_str.StringAccessor.findall)(pat[, case, flags])                     | Find all occurrences of pattern or regular expression in the DataArray.                                                   |
| [`format`](xarray.core.accessor_str.StringAccessor.format.html.md#xarray.core.accessor_str.StringAccessor.format)(\*args, \*\*kwargs)                       | Perform python string formatting on each element of the DataArray.                                                        |
| [`get`](xarray.core.accessor_str.StringAccessor.get.html.md#xarray.core.accessor_str.StringAccessor.get)(i[, default])                                   | Extract character number i from each string in the array.                                                                 |
| [`get_dummies`](xarray.core.accessor_str.StringAccessor.get_dummies.html.md#xarray.core.accessor_str.StringAccessor.get_dummies)(dim[, sep])                     | Return DataArray of dummy/indicator variables.                                                                            |
| [`index`](xarray.core.accessor_str.StringAccessor.index.html.md#xarray.core.accessor_str.StringAccessor.index)(sub[, start, end, side])                    | Return lowest or highest indexes in each strings where the substring is fully contained between [start:end].              |
| [`isalnum`](xarray.core.accessor_str.StringAccessor.isalnum.html.md#xarray.core.accessor_str.StringAccessor.isalnum)()                                       | Check whether all characters in each string are alphanumeric.                                                             |
| [`isalpha`](xarray.core.accessor_str.StringAccessor.isalpha.html.md#xarray.core.accessor_str.StringAccessor.isalpha)()                                       | Check whether all characters in each string are alphabetic.                                                               |
| [`isdecimal`](xarray.core.accessor_str.StringAccessor.isdecimal.html.md#xarray.core.accessor_str.StringAccessor.isdecimal)()                                   | Check whether all characters in each string are decimal.                                                                  |
| [`isdigit`](xarray.core.accessor_str.StringAccessor.isdigit.html.md#xarray.core.accessor_str.StringAccessor.isdigit)()                                       | Check whether all characters in each string are digits.                                                                   |
| [`islower`](xarray.core.accessor_str.StringAccessor.islower.html.md#xarray.core.accessor_str.StringAccessor.islower)()                                       | Check whether all characters in each string are lowercase.                                                                |
| [`isnumeric`](xarray.core.accessor_str.StringAccessor.isnumeric.html.md#xarray.core.accessor_str.StringAccessor.isnumeric)()                                   | Check whether all characters in each string are numeric.                                                                  |
| [`isspace`](xarray.core.accessor_str.StringAccessor.isspace.html.md#xarray.core.accessor_str.StringAccessor.isspace)()                                       | Check whether all characters in each string are spaces.                                                                   |
| [`istitle`](xarray.core.accessor_str.StringAccessor.istitle.html.md#xarray.core.accessor_str.StringAccessor.istitle)()                                       | Check whether all characters in each string are titlecase.                                                                |
| [`isupper`](xarray.core.accessor_str.StringAccessor.isupper.html.md#xarray.core.accessor_str.StringAccessor.isupper)()                                       | Check whether all characters in each string are uppercase.                                                                |
| [`join`](xarray.core.accessor_str.StringAccessor.join.html.md#xarray.core.accessor_str.StringAccessor.join)([dim, sep])                                   | Concatenate strings in a DataArray along a particular dimension.                                                          |
| [`len`](xarray.core.accessor_str.StringAccessor.len.html.md#xarray.core.accessor_str.StringAccessor.len)()                                               | Compute the length of each string in the array.                                                                           |
| [`ljust`](xarray.core.accessor_str.StringAccessor.ljust.html.md#xarray.core.accessor_str.StringAccessor.ljust)(width[, fillchar])                          | Pad right side of each string in the array.                                                                               |
| [`lower`](xarray.core.accessor_str.StringAccessor.lower.html.md#xarray.core.accessor_str.StringAccessor.lower)()                                           | Convert strings in the array to lowercase.                                                                                |
| [`lstrip`](xarray.core.accessor_str.StringAccessor.lstrip.html.md#xarray.core.accessor_str.StringAccessor.lstrip)([to_strip])                               | Remove leading characters.                                                                                                |
| [`match`](xarray.core.accessor_str.StringAccessor.match.html.md#xarray.core.accessor_str.StringAccessor.match)(pat[, case, flags])                         | Determine if each string in the array matches a regular expression.                                                       |
| [`normalize`](xarray.core.accessor_str.StringAccessor.normalize.html.md#xarray.core.accessor_str.StringAccessor.normalize)(form)                               | Return the Unicode normal form for the strings in the datarray.                                                           |
| [`pad`](xarray.core.accessor_str.StringAccessor.pad.html.md#xarray.core.accessor_str.StringAccessor.pad)(width[, side, fillchar])                        | Pad strings in the array up to width.                                                                                     |
| [`partition`](xarray.core.accessor_str.StringAccessor.partition.html.md#xarray.core.accessor_str.StringAccessor.partition)(dim[, sep])                         | Split the strings in the DataArray at the first occurrence of separator sep.                                              |
| [`repeat`](xarray.core.accessor_str.StringAccessor.repeat.html.md#xarray.core.accessor_str.StringAccessor.repeat)(repeats)                                  | Repeat each string in the array.                                                                                          |
| [`replace`](xarray.core.accessor_str.StringAccessor.replace.html.md#xarray.core.accessor_str.StringAccessor.replace)(pat, repl[, n, case, flags, regex])     | Replace occurrences of pattern/regex in the array with some string.                                                       |
| [`rfind`](xarray.core.accessor_str.StringAccessor.rfind.html.md#xarray.core.accessor_str.StringAccessor.rfind)(sub[, start, end])                          | Return highest indexes in each strings in the array where the substring is fully contained between [start:end].           |
| [`rindex`](xarray.core.accessor_str.StringAccessor.rindex.html.md#xarray.core.accessor_str.StringAccessor.rindex)(sub[, start, end])                        | Return highest indexes in each strings where the substring is fully contained between [start:end].                        |
| [`rjust`](xarray.core.accessor_str.StringAccessor.rjust.html.md#xarray.core.accessor_str.StringAccessor.rjust)(width[, fillchar])                          | Pad left side of each string in the array.                                                                                |
| [`rpartition`](xarray.core.accessor_str.StringAccessor.rpartition.html.md#xarray.core.accessor_str.StringAccessor.rpartition)(dim[, sep])                       | Split the strings in the DataArray at the last occurrence of separator sep.                                               |
| [`rsplit`](xarray.core.accessor_str.StringAccessor.rsplit.html.md#xarray.core.accessor_str.StringAccessor.rsplit)(dim[, sep, maxsplit])                     | Split strings in a DataArray around the given separator/delimiter sep.                                                    |
| [`rstrip`](xarray.core.accessor_str.StringAccessor.rstrip.html.md#xarray.core.accessor_str.StringAccessor.rstrip)([to_strip])                               | Remove trailing characters.                                                                                               |
| [`slice`](xarray.core.accessor_str.StringAccessor.slice.html.md#xarray.core.accessor_str.StringAccessor.slice)([start, stop, step])                        | Slice substrings from each string in the array.                                                                           |
| [`slice_replace`](xarray.core.accessor_str.StringAccessor.slice_replace.html.md#xarray.core.accessor_str.StringAccessor.slice_replace)([start, stop, repl])        | Replace a positional slice of a string with another value.                                                                |
| [`split`](xarray.core.accessor_str.StringAccessor.split.html.md#xarray.core.accessor_str.StringAccessor.split)(dim[, sep, maxsplit])                       | Split strings in a DataArray around the given separator/delimiter sep.                                                    |
| [`startswith`](xarray.core.accessor_str.StringAccessor.startswith.html.md#xarray.core.accessor_str.StringAccessor.startswith)(pat)                              | Test if the start of each string in the array matches a pattern.                                                          |
| [`strip`](xarray.core.accessor_str.StringAccessor.strip.html.md#xarray.core.accessor_str.StringAccessor.strip)([to_strip, side])                           | Remove leading and trailing characters.                                                                                   |
| [`swapcase`](xarray.core.accessor_str.StringAccessor.swapcase.html.md#xarray.core.accessor_str.StringAccessor.swapcase)()                                     | Convert strings in the array to be swapcased.                                                                             |
| [`title`](xarray.core.accessor_str.StringAccessor.title.html.md#xarray.core.accessor_str.StringAccessor.title)()                                           | Convert strings in the array to titlecase.                                                                                |
| [`translate`](xarray.core.accessor_str.StringAccessor.translate.html.md#xarray.core.accessor_str.StringAccessor.translate)(table)                              | Map characters of each string through the given mapping table.                                                            |
| [`upper`](xarray.core.accessor_str.StringAccessor.upper.html.md#xarray.core.accessor_str.StringAccessor.upper)()                                           | Convert strings in the array to uppercase.                                                                                |
| [`wrap`](xarray.core.accessor_str.StringAccessor.wrap.html.md#xarray.core.accessor_str.StringAccessor.wrap)(width, \*\*kwargs)                            | Wrap long strings in the array in paragraphs with length less than width.                                                 |
| [`zfill`](xarray.core.accessor_str.StringAccessor.zfill.html.md#xarray.core.accessor_str.StringAccessor.zfill)(width)                                      | Pad each string in the array by prepending '0' characters.                                                                |
