Drop index labels from this DataArray. Parameters ---------- labels : mapping of Hashable to Any Index labels to drop errors : {"raise", "ignore"}, default: "raise" If 'raise', raises a ValueError error if any of the index labels p
(
self,
labels: Mapping[Any, Any] | None = None,
*,
errors: ErrorOptions = "raise",
**labels_kwargs,
)
| 3302 | return self._from_temp_dataset(ds) |
| 3303 | |
| 3304 | def drop_sel( |
| 3305 | self, |
| 3306 | labels: Mapping[Any, Any] | None = None, |
| 3307 | *, |
| 3308 | errors: ErrorOptions = "raise", |
| 3309 | **labels_kwargs, |
| 3310 | ) -> Self: |
| 3311 | """Drop index labels from this DataArray. |
| 3312 | |
| 3313 | Parameters |
| 3314 | ---------- |
| 3315 | labels : mapping of Hashable to Any |
| 3316 | Index labels to drop |
| 3317 | errors : {"raise", "ignore"}, default: "raise" |
| 3318 | If 'raise', raises a ValueError error if |
| 3319 | any of the index labels passed are not |
| 3320 | in the dataset. If 'ignore', any given labels that are in the |
| 3321 | dataset are dropped and no error is raised. |
| 3322 | **labels_kwargs : {dim: label, ...}, optional |
| 3323 | The keyword arguments form of ``dim`` and ``labels`` |
| 3324 | |
| 3325 | Returns |
| 3326 | ------- |
| 3327 | dropped : DataArray |
| 3328 | |
| 3329 | Examples |
| 3330 | -------- |
| 3331 | >>> da = xr.DataArray( |
| 3332 | ... np.arange(25).reshape(5, 5), |
| 3333 | ... coords={"x": np.arange(0, 9, 2), "y": np.arange(0, 13, 3)}, |
| 3334 | ... dims=("x", "y"), |
| 3335 | ... ) |
| 3336 | >>> da |
| 3337 | <xarray.DataArray (x: 5, y: 5)> Size: 200B |
| 3338 | array([[ 0, 1, 2, 3, 4], |
| 3339 | [ 5, 6, 7, 8, 9], |
| 3340 | [10, 11, 12, 13, 14], |
| 3341 | [15, 16, 17, 18, 19], |
| 3342 | [20, 21, 22, 23, 24]]) |
| 3343 | Coordinates: |
| 3344 | * x (x) int64 40B 0 2 4 6 8 |
| 3345 | * y (y) int64 40B 0 3 6 9 12 |
| 3346 | |
| 3347 | >>> da.drop_sel(x=[0, 2], y=9) |
| 3348 | <xarray.DataArray (x: 3, y: 4)> Size: 96B |
| 3349 | array([[10, 11, 12, 14], |
| 3350 | [15, 16, 17, 19], |
| 3351 | [20, 21, 22, 24]]) |
| 3352 | Coordinates: |
| 3353 | * x (x) int64 24B 4 6 8 |
| 3354 | * y (y) int64 32B 0 3 6 12 |
| 3355 | |
| 3356 | >>> da.drop_sel({"x": 6, "y": [0, 3]}) |
| 3357 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 3358 | array([[ 2, 3, 4], |
| 3359 | [ 7, 8, 9], |
| 3360 | [12, 13, 14], |
| 3361 | [22, 23, 24]]) |