【发布时间】:2022-07-06 17:19:10
【问题描述】:
假设我有一个每天观察的熊猫系列:
pd_series = pd.Series(np.random.rand(26281), index = pd.date_range('2022-01-01', '2024-12-31', freq = 'H'))
pd_series
2022-01-01 00:00:00 0.933746
2022-01-01 01:00:00 0.588907
2022-01-01 02:00:00 0.229040
2022-01-01 03:00:00 0.557752
2022-01-01 04:00:00 0.798649
2024-12-30 20:00:00 0.314143
2024-12-30 21:00:00 0.670485
2024-12-30 22:00:00 0.300531
2024-12-30 23:00:00 0.075403
2024-12-31 00:00:00 0.716685
我想要的是用每月平均值替换每个观察值。我知道平均值可以计算为
pd_series.resample('MS').mean()
但是我如何将观察结果放到各自的观察结果中呢?我会很感激任何帮助。非常感谢。
【问题讨论】:
标签: pandas indexing pandas-resample resample