xarray.DataArray.drop_sel (original) (raw)
DataArray.drop_sel(labels=None, *, errors='raise', **labels_kwargs)[source]#
Drop index labels from this DataArray.
Parameters:
- labels (mapping of
Hashable
toAny
) – Index labels to drop - errors (
{"raise", "ignore"}
, default:"raise"
) – If ‘raise’, raises a ValueError error if any of the index labels passed are not in the dataset. If ‘ignore’, any given labels that are in the dataset are dropped and no error is raised. - **labels_kwargs (
{dim: label, ...}
, optional) – The keyword arguments form ofdim
andlabels
Returns:
dropped (DataArray)
Examples
da = xr.DataArray( ... np.arange(25).reshape(5, 5), ... coords={"x": np.arange(0, 9, 2), "y": np.arange(0, 13, 3)}, ... dims=("x", "y"), ... ) da <xarray.DataArray (x: 5, y: 5)> Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates:
- x (x) int64 40B 0 2 4 6 8
- y (y) int64 40B 0 3 6 9 12
da.drop_sel(x=[0, 2], y=9) <xarray.DataArray (x: 3, y: 4)> Size: 96B array([[10, 11, 12, 14], [15, 16, 17, 19], [20, 21, 22, 24]]) Coordinates:
- x (x) int64 24B 4 6 8
- y (y) int64 32B 0 3 6 12
da.drop_sel({"x": 6, "y": [0, 3]}) <xarray.DataArray (x: 4, y: 3)> Size: 96B array([[ 2, 3, 4], [ 7, 8, 9], [12, 13, 14], [22, 23, 24]]) Coordinates:
- x (x) int64 32B 0 2 4 8
- y (y) int64 24B 6 9 12