简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM