How to use xarray .sel() to extract multiple points (given long, lat, time)?

I need help using xarray.
I have a list of points (longitudes, latitudes and dates) for which I need to extract weather data.

So far, I have

weather_by_loc_time  = pd.DataFrame([])

for i,j in zip(latitude,longitude):
    dsloc = ds.sel(latitude=i,longitude=j, method='nearest')
    dot   = dsloc.to_dataframe()
    weather_by_loc_time =  weather_by_loc_time.append(dot)

which gives me data for the entire time series.

If I do

ds.sel(time='2015-01-01', longitude= 340.0, latitude=47.0, method='nearest')

I will get the data for the specific location and 24 hours in the day, which is what I need, but I am not sure how to get this back in a dataframe using the above iteration, or something similar. Thank you all in advance.

Source: Python Questions

LEAVE A COMMENT