Код: Выделить всё
>>> s = pd.Series(np.random.default_rng(seed=123).random(size=5))
>>> s[1] = 10000000 # just a large number
>>> s
0 6.823519e-01
1 1.000000e+07
2 2.203599e-01
3 1.843718e-01
4 1.759059e-01
dtype: float64
>>> s.tail(3).rolling(window=3, min_periods=1).std()
2 NaN
3 0.025447
4 0.023604
dtype: float64
>>> s.tail(4).rolling(window=3, min_periods=1).std()
1 NaN
2 7.071068e+06
3 5.773503e+06
4 0.000000e+00
dtype: float64
>>> s.tail(5).rolling(window=3, min_periods=1).std()
0 NaN
1 7.071067e+06
2 5.773502e+06
3 5.773503e+06
4 0.000000e+00
dtype: float64
Код: Выделить всё
>>> s.tail(3).rolling(window=3, min_periods=1).apply(pd.Series.std)
2 NaN
3 0.025447
4 0.023604
dtype: float64
>>> s.tail(4).rolling(window=3, min_periods=1).apply(pd.Series.std)
1 NaN
2 7.071068e+06
3 5.773503e+06
4 2.360426e-02
dtype: float64
>>> s.tail(5).rolling(window=3, min_periods=1).apply(pd.Series.std)
0 NaN
1 7.071067e+06
2 5.773502e+06
3 5.773503e+06
4 2.360426e-02
dtype: float64
Подробнее здесь: https://stackoverflow.com/questions/796 ... tail-sizes