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 product in each column:

In [3]:
df.cumprod()
Out[3]:
X Y
0 3.0 2.0
1 15.0 NaN
2 30.0 0.0

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

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