python - How to calculate average of every three consecutive elements skipping one element after every iteration -
here list.
1 2 3 4 5 6 7 8 9 10.
i calculate average of every 3 consecutive elements. instance, output be:
na na 2 3 4 5 6 7 8 9
how this?
regards
use rolling window:
in [117]: s = pd.series('1 2 3 4 5 6 7 8 9 10'.split()) in [118]: s out[118]: 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 dtype: object in [119]: s.rolling(3).mean() out[119]: 0 nan 1 nan 2 2.0 3 3.0 4 4.0 5 5.0 6 6.0 7 7.0 8 8.0 9 9.0 dtype: float64
Comments
Post a Comment