Answers for "convert between dataarray and dataset using xarray"

0

convert between dataarray and dataset using xarray

#import xarray
import xarray as xr

#open the dataset
ds = xr.open_dataset(file_name.nc)

#convert between dataarray and dataset
bands = ['var_1', 'var_2', 'var_3', ... , 'var_n']

    #da is a conversion to dataarray where we say we want a dataarray
    #containing only the variables inside bands and we want to convert
    #this subset of data to a dataarray
    #the second line is to convert back to dataset 
da = ds[bands].to_array(dim='enter a dimension of the dataset')
da.to_dataset(dim='enter a dimension of the dataset')
Posted by: Guest on January-24-2021

Code answers related to "convert between dataarray and dataset using xarray"

Python Answers by Framework

Browse Popular Code Answers by Language