how to select variables in a dataset using xarray

Solutions on MaxInterview for how to select variables in a dataset using xarray by the best coders in the world

showing results for - "how to select variables in a dataset using xarray"
Alma
26 Jul 2020
1#import xarray
2import xarray as xr
3
4#open the dataset
5ds = xr.open_dataset(file_name.nc)
6
7#var_name in the following table is to be entered as a string
8
9selection         |    syntax                     |    returns
10--------------------------------------------------------------
11single variable   | ds[var_name]                  | DataArray
12--------------------------------------------------------------
13single variable   | ds[[var_name]]                | Dataset
14--------------------------------------------------------------
15multiple variable | ds[[var_name1, var_name2...]] | Dataset
16
17