I am just a python begginner and I am having some trouble in extracting data from a netcdf file.
For example, in this code I was trying to create a variable with the temperature but it is not appearing at the variable explorer console. Does anyone know why?
import netCDF4 as nc
import numpy as np
fn ='C:/Users/Public/Documents/Python Scripts/MERRA2_300.tavgM_2d_slv_Nx.201001.nc4'
ds = nc.Dataset(fn)
print(ds.variables.keys())
to see all the variables in the netcdf file. Printing the above statement would also give the key for the temperature variable in the file.
Assign it to a variable as shown: temp_variable =ds.variables["#temp#"]
Note: Replace #temp# with the key for temperature variable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.