有没有办法删除不符合特定时间值的xarray数据集中的时间值?

huangapple go评论120阅读模式
英文:

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

问题

这个ERA5数据集由netCDF文件组成,时间以%Y-%m-%dT%h:%M%s %p格式给出,间隔为每小时。因此,对于31天,有744个时间值。我只想提取每天的12:00:00数值,这样我就有了31个数据点。最终,我还想对超过一个月的数据集执行相同操作。

我尝试了一些来自该网站其他帖子的不同方法,其中包括:

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

我还尝试了`ison`函数。

最终我遇到了以下错误:`TypeError: unhashable type: 'DataArray'`。

我确信这与我输入日期时间的方式有关。任何帮助将不胜感激。
英文:

有没有办法删除不符合特定时间值的xarray数据集中的时间值?
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

得分: 1

你正在寻找Xarray的where方法:

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

You are looking for Xarray's where method:

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

huangapple
  • 本文由 发表于 2023年8月5日 11:12:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76840015.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定