I am trying to convert NetCDF to .csv much like this post. I am using a netCDF file with similar variables: 'time', 'lat', 'lon', 'total'
I've reproduced the top answer's code:
import netCDF4
import pandas as pd
file = 'file_path'
nc = netCDF4.Dataset(file, mode='r')
nc.variables.keys()
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
time_var = nc.variables['time']
dtime = netCDF4.num2date(time_var[:],time_var.units)
total = nc.variables['total'][:]
total_ts = pd.Series(total, index=dtime)
total_ts.to_csv('total.csv',index=True, header=True)
however I am getting 2 errors:
UserWarning: WARNING: valid_range not used since it cannot be safely cast to variable data type
dtime = netCDF4.num2date(time_var[:],time_var.units)
and
total_ts = pd.Series(total,index=dtime)
Exception: Data must be 1-dimensional
I am not sure what went wrong since the code is exactly the same and the netCDF file is very similar.