I need to roll through a dataframe and update the estimate in column 2 based on the previous value in column 1 and column 2. I am looking for ideas on how to vectorise this approach/speed it up as it is currently quite costly in the loop format below. The first row is set to 0 as there is no preceding value.
for idx, row in df.iterrows():
if idx == 0:
df.loc[idx, 'column2'] = 0
else:
df.loc[idx, 'column2'] = (df.loc[idx - 1, 'column1'] + df.loc[idx - 1, 'column2'])