 # Difference between cumsum and sum?

anyone can help me in understanding the difference between `cumsum` vs `sum` method. thanks!

Sum is one value, cumsum is list of elements added with all the previous values , say if the elements are 1,2,3 sum is 6 and `cumsum` (cumulative sum) is 1, 3, 6

3 Likes

With sum, you take a certain number of values and perform a sum to get the total.
Cumsum is the cumulative sum of differences between the values.

Day 1 - 5
Day 2 - 10
Sum = 15

If you perform a cumsum you’ll get a dataframe as follow:
Day 1 - 5
Day 2 - 15 (10 + 5)

So for each row, you’ll get the cumulative total up until that point.

Hope it helps

2 Likes

@heitzsimon @PrajwalPrashanth thanks for both nice answers! it makes sense mathematically in your examples, but I dont see the purpose to use cumulative sum on the number of cases. It gives cumulative sum that makes number way to larger than real sum, isnt it (scary outcome!) ?

No, it will not be larger than original sum. Last value of a cumsum will be same as sum.

Better example is
1, 2, 3, 4

sum = 10
cumsum = 1, 3, 7, 10

Cumsum is needed when something is reported daily and you want day wise standings of cases (current cases on any given day)

1 Like