I have a DataFrame, df , in pandas with the df.A and df.B , and I'm trying to create a third series, df.C , which depends on A and B, as well as on the previous result, That is:
C[0]=A[0]
C[n]=A[n] + B[n]*C[n-1]
What is the most efficient way to do this? Ideally, I would not have to go back to the for loop.
Edit
This is the desired result for C given by A and B. Now you just need to figure out how ...
import pandas as pd a = [ 2, 3,-8,-2, 1] b = [ 1, 1, 4, 2, 1] c = [ 2, 5,12,22,23] df = pd.DataFrame({'A': a, 'B': b, 'C': c}) df
source share