英文:
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'`。
我确信这与我输入日期时间的方式有关。任何帮助将不胜感激。
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论