pandas.DataFrame.cumsum() function with example

Spread the love

DataFrame.cumsum()Function : This function return cumulative sum over a DataFrame or Series axis.

Syntax: DataFrame.cumsum(axis=None, skipna=True, *args, **kwargs):

Parameters:
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
The index or the name of the axis. 0 is equivalent to None or ‘index’.

skipna : boolean, default True
Exclude NA/null values. If an entire row/column is NA, the result will be NA.

*args, **kwargs :
Additional keywords have no effect but might be accepted for compatibility with NumPy.

Returns:
cumsum : Series or DataFrame

#python example program on pandas.dataframe.cumsum() function

import numpy as np import pandas as pd df = pd.DataFrame({'A': [1,2,3], 'B': [4, 6, 9], 'C':[9,10,12]}) print(df.cumsum()) print("with axis =1\n",df.cumsum(axis=1))

Output:

   A   B   C
0  1   4   9
1  3  10  19
2  6  19  31
with axis =1
    A   B   C
0  1   5  14
1  2   8  18
2  3  12  24

 

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *