1

I have 3 dataFrames a,b, and c.I want to calculate the sum of a+b+previous output(c).

a=pd.DataFrame([1,2,3,4])
b=pd.DataFrame([1,2,3,4])
c=pd.DataFrame([])
c=c.append(a+b+c.shift(1))

Here I have already to dataframes a and b ,then i created a new dataframe c for saving output of the calculation."c.shift(1) means the previous output.

It shows error.How it is possible??

1
  • It would be helpful if you could give an example of what output you expect. Commented Sep 8, 2020 at 9:12

1 Answer 1

2

Appending will only work in a loop and will not return a value so you could do it but your computation can be reduced to cumsum in this case:

a=pd.DataFrame([1,2,3,4])
b=pd.DataFrame([1,2,3,4])
c=(a+b).cumsum()
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.