xarray.Dataset.drop_sel#
- Dataset.drop_sel(labels=None, *, errors='raise', **labels_kwargs)[source]#
Drop index labels from this dataset.
- Parameters:
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 (
Dataset
)
Examples
>>> data = np.arange(6).reshape(2, 3) >>> labels = ["a", "b", "c"] >>> ds = xr.Dataset({"A": (["x", "y"], data), "y": labels}) >>> ds <xarray.Dataset> Dimensions: (x: 2, y: 3) Coordinates: * y (y) <U1 'a' 'b' 'c' Dimensions without coordinates: x Data variables: A (x, y) int64 0 1 2 3 4 5 >>> 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) int64 1 4 >>> 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) int64 0 2 3 5