MCPcopy
hub / github.com/pydata/xarray / startswith

Method startswith

xarray/core/accessor_str.py:1157–1191  ·  view source on GitHub ↗

Test if the start of each string in the array matches a pattern. The pattern `pat` can either be a ``str`` or array-like of ``str``. If array-like, it will be broadcast and applied elementwise. Parameters ---------- pat : str Character s

(self, pat: str | bytes | Any)

Source from the content-addressed store, hash-verified

1155 return self._apply(func=func, func_args=(pat,), dtype=int)
1156
1157 def startswith(self, pat: str | bytes | Any) -> T_DataArray:
1158 """
1159 Test if the start of each string in the array matches a pattern.
1160
1161 The pattern `pat` can either be a ``str`` or array-like of ``str``.
1162 If array-like, it will be broadcast and applied elementwise.
1163
1164 Parameters
1165 ----------
1166 pat : str
1167 Character sequence. Regular expressions are not accepted.
1168 If array-like, it is broadcast.
1169
1170 Returns
1171 -------
1172 startswith : array of bool
1173 An array of booleans indicating whether the given pattern matches
1174 the start of each string element.
1175
1176 Examples
1177 --------
1178 >>> da = xr.DataArray(["$100", "£23", "100"], dims="x")
1179 >>> da
1180 <xarray.DataArray (x: 3)> Size: 48B
1181 array(['$100', '£23', '100'], dtype='<U4')
1182 Dimensions without coordinates: x
1183 >>> startswith = da.str.startswith("$")
1184 >>> startswith
1185 <xarray.DataArray (x: 3)> Size: 3B
1186 array([ True, False, False])
1187 Dimensions without coordinates: x
1188 """
1189 pat = self._stringify(pat)
1190 func = lambda x, y: x.startswith(y)
1191 return self._apply(func=func, func_args=(pat,), dtype=bool)
1192
1193 def endswith(self, pat: str | bytes | Any) -> T_DataArray:
1194 """

Callers 15

get_public_class_attrsFunction · 0.80
conf.pyFile · 0.80
_skip_signatureFunction · 0.80
label_from_attrsFunction · 0.80
validate_expressionFunction · 0.80
find_stack_levelFunction · 0.80
__init_subclass__Method · 0.80
openMethod · 0.80
open_store_variableMethod · 0.80
openMethod · 0.80

Calls 2

_stringifyMethod · 0.95
_applyMethod · 0.95