1

For example. Let us assume we are having below dataframe:

    Num
0    2 
1    4 
2    1 
3    5 
4    3 

The expected output in another "sum" should be as below:

    Num   sum
0    2    2
1    4    6 (2+4)
2    1    7 (2+4+1)
3    5    12 (2+4+1+5)
4    3    15 (2+4+1+5+3)
SomeOne
  • 497
  • 4
  • 9

1 Answers1

1

This can be achieved using cumsum:

df['sum'] = df['Num'].cumsum()

zabop
  • 6,750
  • 3
  • 39
  • 84
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53