使用python从netcdf导出到csv时创建标头

问题描述 投票:-1回答:1

在Python中,我试图在读取NETCDF后导出csv文件。目前我在csv中没有标题。有人可以帮我写一个标题。提前致谢。

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)
python csv header
1个回答
0
投票

您必须创建标头才能将其写入文件。例如:

evap_csv.name = 'data value'
evap_csv.index.name = 'index value'

然后你的csv文件第一行将是:index value,data value

© www.soinside.com 2019 - 2024. All rights reserved.