xarray.DataArray.drop_sel
xarray.DataArray.drop_sel#
- 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 droperrors (
{"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)> 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 0 2 4 6 8 * y (y) int64 0 3 6 9 12
>>> da.drop_sel(x=[0, 2], y=9) <xarray.DataArray (x: 3, y: 4)> array([[10, 11, 12, 14], [15, 16, 17, 19], [20, 21, 22, 24]]) Coordinates: * x (x) int64 4 6 8 * y (y) int64 0 3 6 12
>>> da.drop_sel({"x": 6, "y": [0, 3]}) <xarray.DataArray (x: 4, y: 3)> array([[ 2, 3, 4], [ 7, 8, 9], [12, 13, 14], [22, 23, 24]]) Coordinates: * x (x) int64 0 2 4 8 * y (y) int64 6 9 12