I want to convert a NetCDF file to CSV format. I have tried the forum for some help, but could not get what I want. I have three variables, a 1D latitude array, 1D longitude array and a 2D variable array. Is it possible to get a CSV format file with columns like LAT, LON, VAR?
I have tried using pandas Dataframe.
from netCDF import Dataset
data = Dataset('popd.nc')
latd=data.variables['latitude']
longd=data.variables['longitude']
popd = data.variables['PopD'][3] # 2D array
popd2015 = pd.DataFrame(popd,index=latd,columns=longd)
popd2015.to_csv('popd2015.csv',index=True,header=True)
The result is a 2d array of my variable with columns at latitude and rows as longitude. But I expect something like three columns with LAT, LON, VAR.