Create a header when exporting from netcdf to csv using python
Create a header when exporting from netcdf to csv using python
In Python I'm trying to export a csv file after reading a NETCDF. Currently I don't have headers in the csv. Can someone help me to write a header. Thanks in advance.
import xarray as xr
ds = xr.open_dataset("../../Data/PYthon/s_daq5_evap_20180825_e56.nc")
evap_pos = ds.sel(lat=-38.2,lon=145.9,method='nearest').compute()
evap_out = evap_pos['evap']
#evap_out.plot()
evap_csv = pd.Series(evap_out, index=ds['time'])
evap_csv.to_csv('evapout56.csv',index=True, header=True)
1 Answer
1
You have to create header to write it to file. For example:
evap_csv.name = 'data value'
evap_csv.index.name = 'index value'
Then your csv-file first line will be: index value,data value
index value,data value
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Your code writes a header here.
– Goyo
Sep 7 '18 at 7:06