0

I have a Data Frame which is around 100x100 and I want to add previous cell + current cell = current cell

An example of the Data Frame:

User     A     B    C   D  
Apple    0     5    6   4 
Orange   23    0    3   5 
Grape    5     10   9   6 
Fruit    67    3    0   9

The desired output:

User     A     B    C   D  
Apple    0     5    11  15 
Orange   23    23   26  31 
Grape    5     15   24  30 
Fruit    67    70   70  79

Using Pandas is this possible to do?

1 Answer 1

1

The operation is called cumulative sum:

df.cumsum(axis=1)

(I assume that "User" is the index).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.