Код: Выделить всё
import pandas as pd
dti = pd.date_range("2017-11-02", "2019-05-21", freq="D", inclusive="both")
s = pd.Series(dti.dayofyear.astype(float), index=dti)
print(s)
# 2017-11-02 306.0
# 2017-11-03 307.0
# 2017-11-04 308.0
# 2017-11-05 309.0
# 2017-11-06 310.0
# ...
# 2019-05-17 137.0
# 2019-05-18 138.0
# 2019-05-19 139.0
# 2019-05-20 140.0
# 2019-05-21 141.0
# Freq: D, Length: 566, dtype: float64
Код: Выделить всё
r = s.resample("3MS", origin=dti[0]).mean()
print(r)
# 2017-11-01 226.659341
# 2018-02-01 76.000000
# 2018-05-01 166.500000
# 2018-08-01 258.500000
# 2018-11-01 227.510870
# 2019-02-01 76.000000
# 2019-05-01 131.000000
# Freq: 3MS, dtype: float64
Код: Выделить всё
dti2 = pd.date_range("2017-10-01", "2019-06-01", freq="D", inclusive="both")
s2 = pd.Series(index=dti2)
s2[s.index] = s.values
s2.resample("3MS").mean()
r2 = s2.resample("3MS").mean()
print(r2)
# 2017-10-01 335.5
# 2018-01-01 45.5
# 2018-04-01 136.0
# 2018-07-01 227.5
# 2018-10-01 319.5
# 2019-01-01 45.5
# 2019-04-01 116.0
# Freq: 3MS, dtype: float64
Подробнее здесь: https://stackoverflow.com/questions/798 ... rt-of-year
Мобильная версия