xarray.Dataset.drop

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

Drop variables or index labels from this dataset.

Parameters
  • labels (hashable or iterable of hashables) – Name(s) of variables or index labels to drop. If dim is not None, labels can be any array-like.

  • dim (None or hashable, optional) – Dimension along which to drop index labels. By default (if dim is None), drops variables rather than index labels.

  • errors ({'raise', 'ignore'}, optional) – If ‘raise’ (default), raises a ValueError error if any of the variable or 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(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(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