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)
| 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 | """ |