xarray.core.accessor_str.StringAccessor

class xarray.core.accessor_str.StringAccessor(obj)

Vectorized string functions for string-like arrays.

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

>>> da = xr.DataArray(['some', 'text', 'in', 'an', 'array'])
>>> ds.str.len()
<xarray.DataArray (dim_0: 5)>
array([4, 4, 2, 2, 5])
Dimensions without coordinates: dim_0
__init__(obj)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(obj)

Initialize self.

capitalize()

Convert strings in the array to be capitalized.

center(width[, fillchar])

Filling left and right side of strings in the array with an additional character.

contains(pat[, case, flags, regex])

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

count(pat[, flags])

Count occurrences of pattern in each string of the array.

decode(encoding[, errors])

Decode character string in the array using indicated encoding.

encode(encoding[, errors])

Encode character string in the array using indicated encoding.

endswith(pat)

Test if the end of each string element matches a pattern.

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].

get(i)

Extract element from indexable in each element in the array.

index(sub[, start, end, side])

Return lowest or highest indexes in each strings where the substring is fully contained between [start:end].

isalnum()

Check whether all characters in each string are alphanumeric.

isalpha()

Check whether all characters in each string are alphabetic.

isdecimal()

Check whether all characters in each string are decimal.

isdigit()

Check whether all characters in each string are digits.

islower()

Check whether all characters in each string are lowercase.

isnumeric()

Check whether all characters in each string are numeric.

isspace()

Check whether all characters in each string are spaces.

istitle()

Check whether all characters in each string are titlecase.

isupper()

Check whether all characters in each string are uppercase.

len()

Compute the length of each element in the array.

ljust(width[, fillchar])

Filling right side of strings in the array with an additional character.

lower()

Convert strings in the array to lowercase.

lstrip([to_strip])

Remove leading and trailing characters.

match(pat[, case, flags])

Determine if each string matches a regular expression.

pad(width[, side, fillchar])

Pad strings in the array up to width.

repeat(repeats)

Duplicate each string in the array.

replace(pat, repl[, n, case, flags, regex])

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

rfind(sub[, start, end])

Return highest indexes in each strings in the array where the substring is fully contained between [start:end].

rindex(sub[, start, end])

Return highest indexes in each strings where the substring is fully contained between [start:end].

rjust(width[, fillchar])

Filling left side of strings in the array with an additional character.

rstrip([to_strip])

Remove leading and trailing characters.

slice([start, stop, step])

Slice substrings from each element in the array.

slice_replace([start, stop, repl])

Replace a positional slice of a string with another value.

startswith(pat)

Test if the start of each string element matches a pattern.

strip([to_strip, side])

Remove leading and trailing characters.

swapcase()

Convert strings in the array to be swapcased.

title()

Convert strings in the array to titlecase.

translate(table)

Map all characters in the string through the given mapping table.

upper()

Convert strings in the array to uppercase.

wrap(width, **kwargs)

Wrap long strings in the array to be formatted in paragraphs with length less than a given width.

zfill(width)

Pad strings in the array by prepending ‘0’ characters.