最近需要将气象nc转为csv数据,但是网上的程序太复杂了不适合新手。
path = r"G:/Python_/weather/wind/data.nc"
data = xr.open_dataset(path)
year = 1980
while year < 2018:
point_df = pd.DataFrame()
out_path = "G:/Python_/weather/wind/"+str(year)+".csv"
month = 1
i =0
while month<=12:
time_index = os.path.join(str(year) + '-' + str(month))
print('processing'+time_index+'!!!')
ds = data['w'].sel(time=time_index)
point_df.loc[i,'time'] = time_index
point_df.loc[i,'wind'] = np.mean(ds)
i+=1
month +=1
point_df.to_csv(out_path)
year+=1
mean是因为我要对全流域进行平均,以便作出该气象因子的年际变化折线图