Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Have a look in the solutions folder and edit and run the script netcdf_to_pandas.py. This shows how to extract some metadata from the previous netCDF file, and also some value arrays and convert into a pandas dataframe. The code is also here:

Code Block
languagepy
collapsetrue
import metview as mv
import pandas as pd

nc = mv.read("madis-maritime.nc")

# print some global fields
print('Variables: \n', nc.variables())
print('Global attributes: \n', nc.global_attributes())

# extract certain variables - setcurrent() followed by values()
nc.setcurrent('latitude')
lats = nc.values()
nc.setcurrent('longitude')
lons = nc.values()
nc.setcurrent('temperature')
temps = nc.values()
print('temperature attributes: \n', nc.attributes())

# create a dictionary in order to convert to pandas
pddict = {'latitude'    : lats,
          'longitude'   : lons,
          'temperature' : temps}

df = pd.DataFrame(pddict)
print('Dataframe: \n', df)
print('temperature describe: \n', df.temperature.describe())