Tsallaka zuwa abun ciki
Justice Tech School

Cumulative and Rolling

cumsum, cumprod and rolling windows track change over time.

Example
s = pd.Series([1, 2, 3, 4, 5])
print(s.cumsum().tolist())
print(s.rolling(3).mean().tolist())
print(s.diff().tolist(), s.pct_change().round(2).tolist())

Result

[1, 3, 6, 10, 15]
[nan, nan, 2.0, 3.0, 4.0]
[nan, 1.0, 1.0, 1.0, 1.0] [nan, 1.0, 0.5, 0.33, 0.25]

Exercise

Running total.

s.()

Quiz Test

What does rolling(3) do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.