# xarray.Dataset.drop_vars

#### Dataset.drop_vars(names, , errors='raise')[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L5882-L6039)

Drop variables from this dataset.

* **Parameters:**
  * **names** (`Hashable` or [iterable](https://docs.python.org/3/glossary.html#term-iterable) of `Hashable` or `Callable`) – Name(s) of variables to drop. If a Callable, this object is passed as its
    only argument and its result is used.
  * **errors** (`{"raise", "ignore"}`, *default*: `"raise"`) – If ‘raise’, raises a ValueError error if any of the variable
    passed are not in the dataset. If ‘ignore’, any given names that are in the
    dataset are dropped and no error is raised.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('920963ce-f69e-45fc-a5ca-f26e1bd31bb4','053bb17a-ea1f-4c09-a327-7d86f421529c','d3fb20d2-e09e-40d8-bc04-8bbf981fda95','../lite/tree/../notebooks/index.html?path=aeef913a_2140_4dfc_997a_995508f5d175.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> dataset = xr.Dataset(
...     {
...         "temperature": (
...             ["time", "latitude", "longitude"],
...             [[[25.5, 26.3], [27.1, 28.0]]],
...         ),
...         "humidity": (
...             ["time", "latitude", "longitude"],
...             [[[65.0, 63.8], [58.2, 59.6]]],
...         ),
...         "wind_speed": (
...             ["time", "latitude", "longitude"],
...             [[[10.2, 8.5], [12.1, 9.8]]],
...         ),
...     },
...     coords={
...         "time": pd.date_range("2023-07-01", periods=1),
...         "latitude": [40.0, 40.2],
...         "longitude": [-75.0, -74.8],
...     },
... )
>>> dataset
<xarray.Dataset> Size: 136B
Dimensions:      (time: 1, latitude: 2, longitude: 2)
Coordinates:
  * time         (time) datetime64[us] 8B 2023-07-01
  * latitude     (latitude) float64 16B 40.0 40.2
  * longitude    (longitude) float64 16B -75.0 -74.8
Data variables:
    temperature  (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0
    humidity     (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6
    wind_speed   (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
```

Drop the ‘humidity’ variable

```pycon
>>> dataset.drop_vars(["humidity"])
<xarray.Dataset> Size: 104B
Dimensions:      (time: 1, latitude: 2, longitude: 2)
Coordinates:
  * time         (time) datetime64[us] 8B 2023-07-01
  * latitude     (latitude) float64 16B 40.0 40.2
  * longitude    (longitude) float64 16B -75.0 -74.8
Data variables:
    temperature  (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0
    wind_speed   (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
```

Drop the ‘humidity’, ‘temperature’ variables

```pycon
>>> dataset.drop_vars(["humidity", "temperature"])
<xarray.Dataset> Size: 72B
Dimensions:     (time: 1, latitude: 2, longitude: 2)
Coordinates:
  * time        (time) datetime64[us] 8B 2023-07-01
  * latitude    (latitude) float64 16B 40.0 40.2
  * longitude   (longitude) float64 16B -75.0 -74.8
Data variables:
    wind_speed  (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
```

Drop all indexes

```pycon
>>> dataset.drop_vars(lambda x: x.indexes)
<xarray.Dataset> Size: 96B
Dimensions:      (time: 1, latitude: 2, longitude: 2)
Dimensions without coordinates: time, latitude, longitude
Data variables:
    temperature  (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0
    humidity     (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6
    wind_speed   (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
```

Attempt to drop non-existent variable with errors=”ignore”

```pycon
>>> dataset.drop_vars(["pressure"], errors="ignore")
<xarray.Dataset> Size: 136B
Dimensions:      (time: 1, latitude: 2, longitude: 2)
Coordinates:
  * time         (time) datetime64[us] 8B 2023-07-01
  * latitude     (latitude) float64 16B 40.0 40.2
  * longitude    (longitude) float64 16B -75.0 -74.8
Data variables:
    temperature  (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0
    humidity     (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6
    wind_speed   (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
```

Attempt to drop non-existent variable with errors=”raise”

```pycon
>>> dataset.drop_vars(["pressure"], errors="raise")
Traceback (most recent call last):
ValueError: These variables cannot be found in this dataset: ['pressure']
```

<div id="d3fb20d2-e09e-40d8-bc04-8bbf981fda95" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('920963ce-f69e-45fc-a5ca-f26e1bd31bb4','d3fb20d2-e09e-40d8-bc04-8bbf981fda95')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('920963ce-f69e-45fc-a5ca-f26e1bd31bb4','d3fb20d2-e09e-40d8-bc04-8bbf981fda95')">Open In Tab</button></div><div id="053bb17a-ea1f-4c09-a327-7d86f421529c" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – Raised if you attempt to drop a variable which is not present, and the kwarg `errors='raise'`.
* **Returns:**
  **dropped** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset))

#### SEE ALSO
[`DataArray.drop_vars`](xarray.DataArray.drop_vars.html.md#xarray.DataArray.drop_vars)
