Drop variables from this dataset. Parameters ---------- names : Hashable or 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", "ig
(
self,
names: str | Iterable[Hashable] | Callable[[Self], str | Iterable[Hashable]],
*,
errors: ErrorOptions = "raise",
)
| 5787 | ) |
| 5788 | |
| 5789 | def drop_vars( |
| 5790 | self, |
| 5791 | names: str | Iterable[Hashable] | Callable[[Self], str | Iterable[Hashable]], |
| 5792 | *, |
| 5793 | errors: ErrorOptions = "raise", |
| 5794 | ) -> Self: |
| 5795 | """Drop variables from this dataset. |
| 5796 | |
| 5797 | Parameters |
| 5798 | ---------- |
| 5799 | names : Hashable or iterable of Hashable or Callable |
| 5800 | Name(s) of variables to drop. If a Callable, this object is passed as its |
| 5801 | only argument and its result is used. |
| 5802 | errors : {"raise", "ignore"}, default: "raise" |
| 5803 | If 'raise', raises a ValueError error if any of the variable |
| 5804 | passed are not in the dataset. If 'ignore', any given names that are in the |
| 5805 | dataset are dropped and no error is raised. |
| 5806 | |
| 5807 | Examples |
| 5808 | -------- |
| 5809 | |
| 5810 | >>> dataset = xr.Dataset( |
| 5811 | ... { |
| 5812 | ... "temperature": ( |
| 5813 | ... ["time", "latitude", "longitude"], |
| 5814 | ... [[[25.5, 26.3], [27.1, 28.0]]], |
| 5815 | ... ), |
| 5816 | ... "humidity": ( |
| 5817 | ... ["time", "latitude", "longitude"], |
| 5818 | ... [[[65.0, 63.8], [58.2, 59.6]]], |
| 5819 | ... ), |
| 5820 | ... "wind_speed": ( |
| 5821 | ... ["time", "latitude", "longitude"], |
| 5822 | ... [[[10.2, 8.5], [12.1, 9.8]]], |
| 5823 | ... ), |
| 5824 | ... }, |
| 5825 | ... coords={ |
| 5826 | ... "time": pd.date_range("2023-07-01", periods=1), |
| 5827 | ... "latitude": [40.0, 40.2], |
| 5828 | ... "longitude": [-75.0, -74.8], |
| 5829 | ... }, |
| 5830 | ... ) |
| 5831 | >>> dataset |
| 5832 | <xarray.Dataset> Size: 136B |
| 5833 | Dimensions: (time: 1, latitude: 2, longitude: 2) |
| 5834 | Coordinates: |
| 5835 | * time (time) datetime64[us] 8B 2023-07-01 |
| 5836 | * latitude (latitude) float64 16B 40.0 40.2 |
| 5837 | * longitude (longitude) float64 16B -75.0 -74.8 |
| 5838 | Data variables: |
| 5839 | temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 |
| 5840 | humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 |
| 5841 | wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8 |
| 5842 | |
| 5843 | Drop the 'humidity' variable |
| 5844 | |
| 5845 | >>> dataset.drop_vars(["humidity"]) |
| 5846 | <xarray.Dataset> Size: 104B |