Returns an array with dropped variables. 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 : {"rais
(
self,
names: str | Iterable[Hashable] | Callable[[Self], str | Iterable[Hashable]],
*,
errors: ErrorOptions = "raise",
)
| 3181 | return self.transpose() |
| 3182 | |
| 3183 | def drop_vars( |
| 3184 | self, |
| 3185 | names: str | Iterable[Hashable] | Callable[[Self], str | Iterable[Hashable]], |
| 3186 | *, |
| 3187 | errors: ErrorOptions = "raise", |
| 3188 | ) -> Self: |
| 3189 | """Returns an array with dropped variables. |
| 3190 | |
| 3191 | Parameters |
| 3192 | ---------- |
| 3193 | names : Hashable or iterable of Hashable or Callable |
| 3194 | Name(s) of variables to drop. If a Callable, this object is passed as its |
| 3195 | only argument and its result is used. |
| 3196 | errors : {"raise", "ignore"}, default: "raise" |
| 3197 | If 'raise', raises a ValueError error if any of the variable |
| 3198 | passed are not in the dataset. If 'ignore', any given names that are in the |
| 3199 | DataArray are dropped and no error is raised. |
| 3200 | |
| 3201 | Returns |
| 3202 | ------- |
| 3203 | dropped : Dataset |
| 3204 | New Dataset copied from `self` with variables removed. |
| 3205 | |
| 3206 | Examples |
| 3207 | -------- |
| 3208 | >>> data = np.arange(12).reshape(4, 3) |
| 3209 | >>> da = xr.DataArray( |
| 3210 | ... data=data, |
| 3211 | ... dims=["x", "y"], |
| 3212 | ... coords={"x": [10, 20, 30, 40], "y": [70, 80, 90]}, |
| 3213 | ... ) |
| 3214 | >>> da |
| 3215 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 3216 | array([[ 0, 1, 2], |
| 3217 | [ 3, 4, 5], |
| 3218 | [ 6, 7, 8], |
| 3219 | [ 9, 10, 11]]) |
| 3220 | Coordinates: |
| 3221 | * x (x) int64 32B 10 20 30 40 |
| 3222 | * y (y) int64 24B 70 80 90 |
| 3223 | |
| 3224 | Removing a single variable: |
| 3225 | |
| 3226 | >>> da.drop_vars("x") |
| 3227 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 3228 | array([[ 0, 1, 2], |
| 3229 | [ 3, 4, 5], |
| 3230 | [ 6, 7, 8], |
| 3231 | [ 9, 10, 11]]) |
| 3232 | Coordinates: |
| 3233 | * y (y) int64 24B 70 80 90 |
| 3234 | Dimensions without coordinates: x |
| 3235 | |
| 3236 | Removing a list of variables: |
| 3237 | |
| 3238 | >>> da.drop_vars(["x", "y"]) |
| 3239 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 3240 | array([[ 0, 1, 2], |