1

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.

Mark
  • 7,785
  • 2
  • 14
  • 34
  • 1
    Hi Matthew! Welcome to StackOverflow! The code you have works for dataframes, but it seems like your data isn't a dataframe. – Mark Aug 05 '23 at 04:23
  • Why didn't you simply download the 12:00 value in the first place? ~30 times less data to handle and store. with cdo though you could just do cdo selhour,12 i think. – ClimateUnboxed Aug 05 '23 at 10:26
  • for xarray data sets / data arrays, see also [Indexing and selecting data](https://docs.xarray.dev/en/stable/user-guide/indexing.html) – FObersteiner Aug 06 '23 at 07:40

1 Answers1

1

You are looking for Xarray's where method:

df2 = df.where(df.time.dt.hour == 12, drop=True)
jhamman
  • 5,867
  • 19
  • 39