xarray.Dataset.drop_sel

Dataset.drop_sel(self, labels=None, *, errors='raise', **labels_kwargs)

Drop index labels from this dataset.

Parameters
  • labels (Mapping[Hashable, Any]) – Index labels to drop

  • errors ({'raise', 'ignore'}, optional) – If ‘raise’ (default), 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 of dim and labels

Returns

dropped

Return type

Dataset

Examples

>>> data = np.random.randn(2, 3)
>>> labels = ['a', 'b', 'c']
>>> ds = xr.Dataset({'A': (['x', 'y'], data), 'y': labels})
>>> ds.drop_sel(y=['a', 'c'])
<xarray.Dataset>
Dimensions:  (x: 2, y: 1)
Coordinates:
  * y        (y) <U1 'b'
Dimensions without coordinates: x
Data variables:
    A        (x, y) float64 -0.3454 0.1734
>>> ds.drop_sel(y='b')
<xarray.Dataset>
Dimensions:  (x: 2, y: 2)
Coordinates:
  * y        (y) <U1 'a' 'c'
Dimensions without coordinates: x
Data variables:
    A        (x, y) float64 -0.3944 -1.418 1.423 -1.041