How do I obtain the rolling values of some length n of a pandas series of value ?
For example, if I have the following:
df = pd.DataFrame({'temperature': [0, 1, 2, np.nan, 4, 2, 0.8, 4, 8.8, 7.12]})
how do I obtain the moving values of length n, i.e. something like, if n=3:
[NaN, NaN, 0], [NaN, 0, 1],..., [4, 8.8, 7.12]
EDIT:
If I use pandas rolling, as:
roll = pd.Series.rolling(df, 3).mean()
then roll is the moving averages of the series.
Here, I do not want the averages of every moving set of 3 values, but these sets of 3 values.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…