pandas cumprod
时间: 2023-10-13 08:20:09 浏览: 32
pandas.cumprod() is a function in the pandas library that returns the cumulative product of the elements in a pandas Series or DataFrame. It computes the product of all the elements from the beginning of the Series or DataFrame up to the current position.
Syntax:
```
DataFrame.cumprod(axis=None, skipna=True, *args, **kwargs)
```
Parameters:
- axis: 0 or 'index' for rows and 1 or 'columns' for columns. By default, it is None and applies cumprod() on the entire DataFrame.
- skipna: If True, it skips NaN values while performing the cumprod() operation, otherwise, it returns NaN.
Returns:
- A new pandas Series or DataFrame with the cumulative product of the elements.
Example:
```
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3, 4]})
print(df.cumprod())
```
Output:
```
A
0 1
1 2
2 6
3 24
```