在10年内每天获得最大价值

时间:2020-08-05 16:32:44

标签: python pandas datetime

这是我的代码,并获得10年中每天的最大值。

tmax = weather.set_index(['Date']).resample('D').max().resample('D').max() 看起来像这样:

enter image description here

但是现在无论年份如何,我每天都只想要最大值,因此它将是365行。 假设我没有leap年,索引是日期时间。 谢谢

1 个答案:

答案 0 :(得分:0)

如果有人处于相同的情况,我发现以下解决方案:

使用年份编号创建新列

tmax['dayofyear'] = tmax.index.dayofyear

现在,它们按天数分组,只剩下最大值。

tmax = tmax.groupby('dayofyear').max()