Is there a way to delete time values in an xarray dataset that does not meet a certain time value?

229 Views Asked by At

Description of the data set This ERA5 dataset, made up of netCDF files, comes in time values of %Y-%m-%dT%h:%M%s %p and they are given hourly. So, for 31 days, there are 744-time values. I only want to take the 12:00:00 value for each day so that I have 31 data points. Eventually I want to do this for data sets longer than a month as well.

I tried a few different things from various other posts on this site. A few of them include:

df = df[df['time'].dt.hour == 12]

I also tried the ison function.

I ended up getting the following error: TypeError: unhashable type: 'DataArray'

I am sure it has something to do with the way I am inputting datetime. Any help would be greatly appreciated.

1

There are 1 best solutions below

0
jhamman On

You are looking for Xarray's where method:

df2 = df.where(df.time.dt.hour == 12, drop=True)