import pandas as pd
import xarray as xr
from netCDF4 import Dataset
nc_file = (r"C:\Users\DELL 3090\Desktop\Projection\RF_58\pr_Amon_AWI-CM-1-1-MR_ssp585_mm_month.nc")
NC = xr.open_dataset(nc_file)
#define locations and station id
lat=[13.3,7.5,8.5,7.9,9,7.8,11.3,14.3,14.2,7]
lon=[39.8,34.3,39.8,38.7,38.8,39.9,37.5,39.5,38.9,39.9]
name=['Abala','Abobo','Abomsa','Adamitulu','AddisAbabaBole','Adele','Adet','Adigrat','Adwa','Agarfa']
Newdf = pd.DataFrame([])
for i,j,id in zip(lat,lon,name):
dsloc = NC.sel(lat=i,lon=j,method='nearest')
DT=dsloc.to_dataframe()
# insert the name with your preferred column title:
Newdf=Newdf._append(DT,sort=True)
Newdf.to_netcdf('C:/Users/DELL 3090/Desktop/Projection\RF_58/pr_Amon_AWI-CM-1-1 MR_ssp585_mm_month111.nc', index=True, header=True)
但最终python回答了此错误:
file〜naconda3 nvs nv_resaerch \ lib \ site-packages \ panda