Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame([[3.0, 2.0],
                   [5.0, np.nan],
                   [2.0, 0.0]],
                   columns=list('XY'))
df
Out[2]:
X Y
0 3.0 2.0
1 5.0 NaN
2 2.0 0.0

By default, iterates over rows and finds the sum in each column:

In [3]:
df.cumsum()
Out[3]:
X Y
0 3.0 2.0
1 8.0 NaN
2 10.0 2.0

To iterate over columns and find the sum in each row, use axis=1:

In [4]:
df.cumsum(axis=1)
Out[4]:
X Y
0 3.0 5.0
1 5.0 NaN
2 2.0 2.0