So the cumulative sum is calculating the sum for each member up to the current one. This is extremely useful for data science and many business areas. The first result is the output of our number series. The second one we calculate the cumulative sum for this series - as you can see np.NaN ( similar to None but optimized for pandas needs) doesn't break the sum. You can change this behavior by:

s.cumsum(skipna=False)

which will result in:

0 2.0
1 NaN
2 NaN
3 NaN
4 NaN
dtype: float64

Now lets check a more complicated examples including grouping on pandas dataframes on one and more columns. Having this data:

table 1

Country

Company

Date

Sells

0

India

Samsung

10/09/18

15

1

India

Samsung

10/09/18

81

2

USA

Samsung

10/09/18

29

3

France

Samsung

10/10/18

33

4

India

Samsung

10/10/18

21

5

India

LG

10/10/18

42

6

Germany

LG

10/09/18

67

7

USA

LG

10/09/18

35

8

Brazil

LG

10/09/18

2

9

Tony

LG

10/10/18

34

10

India

Sony

10/10/18

21

11

Germany

Sony

10/10/18

50

12

India

Sony

10/10/18

10

13

India

Sony

10/10/18

26

14

Brazil

Sony

10/10/18

53

table 2

Company

Date

Sells

Promo

0

Samsung

08/09/2018

11

54

1

Samsung

10/09/2018

8

56

2

Samsung

09/09/2018

43

54

3

Samsung

04/09/2018

4

4

4

Sony

08/09/2018

45

3

5

Sony

10/09/2018

534

34

6

Sony

09/09/2018

42

32

7

Sony

04/09/2018

32

15

If we want to calculate the cumulative sum of Promotions(Promo) per Company and for every date we can do: