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"])
>>> da.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])

Pad left and right side of each string in the array.

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

Test if pattern or regex is contained within each 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 in the array 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[, default])

Extract character number i from each string 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 string in the array.

ljust(width[, fillchar])

Pad right side of each string in the array.

lower()

Convert strings in the array to lowercase.

lstrip([to_strip])

Remove leading characters.

match(pat[, case, flags])

Determine if each string in the array 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])

Pad left side of each string in the array.

rstrip([to_strip])

Remove trailing characters.

slice([start, stop, step])

Slice substrings from each string 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 in the array 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 characters of each string through the given mapping table.

upper()

Convert strings in the array to uppercase.

wrap(width, **kwargs)

Wrap long strings in the array in paragraphs with length less than width.

zfill(width)

Pad each string in the array by prepending ‘0’ characters.