0

I have selected multiple netCDF4 files from my folder.I need to convert selected variables from all such files to .csv format by looping.

Can you suggest me some ways to do such conversion I have created a dataframe and tried tio export using this conversion

d=np.dstack((dtime,lat,lon,alt,range_ku,model_dry_tropo_corr,rad_wet_tropo_corr,iono_corr_alt_ku,sea_state_bias_ku,mean_sea_surface,solid_earth_tide,pole_tide))
#print(d)
df=pd.DataFrame(d[0,:], columns = ['dtime','lat','lon','alt','range_ku','model_dry_tropo_corr','rad_wet_tropo_corr','iono_corr_alt_ku','sea_state_bias_ku','mean_sea_surface','solid_earth_tide','pole_tide'])
#print(df)
df.to_csv("F:/data/New folder/"+file1.split('\\')[1][:-3]+".csv")    
  • I would suggest to read the NetCDF file with Xarray, convert it to a Pandas dataframe, and let Pandas export it to CSV files. See e.g. https://stackoverflow.com/questions/14035148/import-netcdf-file-to-pandas-dataframe and https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html – Bart Jun 10 '19 at 06:48
  • p.s. possible duplicate of https://stackoverflow.com/questions/44359869/convert-netcdf-file-to-csv-or-text-using-python – Bart Jun 10 '19 at 06:50
  • Yeah!I have created pandas dataframe for my file.But I feel difficulty in exporting all files at same time. – tamil selvan.M Jun 11 '19 at 04:24
  • Can you edit/update your question with the new code you wrote? – Bart Jun 11 '19 at 04:38

0 Answers0