Shayan
Shayan

Reputation: 6305

is there a method to expand an operation on a column of dataframe in pandas?

exactly I mean :
suppose we have this pandas.DataFrame:

enter image description here

and we want to expand summation on it! expected result:

enter image description here

Note that I want to know if there is a method in pandas for this purpose or not? and I know that I can write code with for loops and etc. I'm looking for a method or module in pandas package for this kind of calculations.
is there a pre-write method for this in pandas?

Upvotes: 2

Views: 85

Answers (1)

I'mahdi
I'mahdi

Reputation: 24049

You can use cumsum() like below:

df = pd.DataFrame({
    'col': [2,3,4,5]
})

df.cumsum()

Output:

    col
0   2
1   5
2   9
3   14

Upvotes: 5

Related Questions