pandas.Series.cumsum#

Series.cumsum(axis=0, skipna=True, *args, **kwargs)[source]#

Return cumulative sum over a Series.

Returns a Series of the same size containing the cumulative sum.

Parameters:
axis{0 or ‘index’}, default 0

This parameter is unused and defaults to 0.

skipnabool, default True

Exclude NA/null values. If entire series is NA, the result will be NA.

*args, **kwargs

Additional keywords have no effect but might be accepted for compatibility with NumPy.

Returns:
Series

Return cumulative sum of Series.

See also

core.window.expanding.Expanding.sum

Similar functionality but ignores NaN values.

Series.sum

Return the sum over Series.

Series.cummax

Return cumulative maximum.

Series.cummin

Return cumulative minimum.

Series.cumprod

Return cumulative product.

Examples

>>> s = pd.Series([2, np.nan, 5, -1, 0])
>>> s
0    2.0
1    NaN
2    5.0
3   -1.0
4    0.0
dtype: float64

By default, NA values are ignored.

>>> s.cumsum()
0    2.0
1    NaN
2    7.0
3    6.0
4    6.0
dtype: float64

To include NA values in the operation, use skipna=False

>>> s.cumsum(skipna=False)
0    2.0
1    NaN
2    NaN
3    NaN
4    NaN
dtype: float64