[Advanced Python (Time Series Analysis)](https://www.amazon.co.jp/%E6%99%82%E7%B3%BB%E5%88%97%E8%A7%A3%E6%9E % 90-% E8% 87% AA% E5% B7% B1% E5% 9B% 9E% E5% B8% B0% E5% 9E% 8B% E3% 83% A2% E3% 83% 87% E3% 83% AB% E3% 83% BB% E7% 8A% B6% E6% 85% 8B% E7% A9% BA% E9% 96% 93% E3% 83% A2% E3% 83% 87% E3% 83% AB% E3% 83% BB% E7% 95% B0% E5% B8% B8% E6% A4% 9C% E7% 9F% A5-Advanced-% E5% B3% B6% E7% 94% B0-% E7% 9B% B4% E5% B8% 8C / dp / 4320125010 / ref = pd_aw_sbs_14_4 / 355-0401449-3667847? _Encoding = UTF8 & pd_rd_i = 4320125010 & pd_rd_r = 1b383d15-c4b7-4c76-a51b-4defd44ba9e4 & pd_w I read 0dece788c310 & pf_rd_r = KNHHHK22TY4MB1ZQ5181 & psc = 1 & refRID = KNHHHK22TY4MB1ZQ5181). The rolling () method is used when taking the moving average. I have some questions, so this is a simple verification memo.
-> Included.
series = pd.Series(range(10))
print(series)
# 0 0
# 1 1
# 2 2
# 3 3
# 4 4
# 5 5
# 6 6
# 7 7
# 8 8
# 9 9
series_size3 = series.rolling(window=3).mean()
print(series_size3)
# 0 NaN
# 1 NaN
# 2 1.0
# 3 2.0
# 4 3.0
# 5 4.0
# 6 5.0
# 7 6.0
# 8 7.0
# 9 8.0
-> Included.
series_size3 = series.rolling(window=3, center=True).mean()
print(series_size3)
# 0 NaN
# 1 1.0
# 2 2.0
# 3 3.0
# 4 4.0
# 5 5.0
# 6 6.0
# 7 7.0
# 8 8.0
# 9 NaN
-> The top line is taken first.
series_size2 = series.rolling(window=2, center=True).mean()
print(series_size2)
# 0 NaN
# 1 0.5
# 2 1.5
# 3 2.5
# 4 3.5
# 5 4.5
# 6 5.5
# 7 6.5
# 8 7.5
# 9 8.5
series_size4 = series.rolling(window=4, center=True).mean()
print(series_size4)
# 0 NaN
# 1 NaN
# 2 1.5
# 3 2.5
# 4 3.5
# 5 4.5
# 6 5.5
# 7 6.5
# 8 7.5
# 9 NaN
-> No deviation
series = pd.Series([100, 1, 2, 3, 4, 5, 6, 7, 8, 9])
print(series)
# 0 100
# 1 1
# 2 2
# 3 3
# 4 4
# 5 5
# 6 6
# 7 7
# 8 8
# 9 9
series_size4 = series.rolling(window=4).mean()
series_size4_shift = series.rolling(window=4).mean().shift(-2)
print(series_size4)
print(series_size4_shift)
# 0 NaN
# 1 NaN
# 2 NaN
# 3 26.5
# 4 2.5
# 5 3.5
# 6 4.5
# 7 5.5
# 8 6.5
# 9 7.5
# 0 NaN
# 1 26.5
# 2 2.5
# 3 3.5
# 4 4.5
# 5 5.5
# 6 6.5
# 7 7.5
# 8 NaN
# 9 NaN
Recommended Posts