0

I have imported a netcdf file into Python and am now trying to access specific variables in the file (of over 100 variables). This is the code i'm using in order to just print and read each variables:

ds = Dataset(fn, 'r')
yr = ds.variables['Year']
print(yr[:])

This returns me with the error:

ValueError: invalid literal for int() with base 10: '-1e+35,1e+35'

Any idea on how to overcome this error? This is the only way I can find that is used to print each variable.

Eleanor
  • 1
  • 1

1 Answers1

1

Using the raw netcdf library is deprecated

try something like:

import xarray as xr
dataset = xr.open_dataset("path/to/your/dataset.nc")
[print(var) for var in dataset.variables]

to print out the variables

the module / library Xarray is very good to handle climate data

  • yes I finally realise that after talking to some colleagues, thankfully my colleague had the data as a csv file that I could take from him but I might try this at a later point to see if it works! it will forever bother me that I couldn't get around it. – Eleanor Feb 01 '22 at 06:10