python - Pandas dataframe: multiply row by previous row -


i have dataframe input:

                       df1                             b      c 20/08/17    0.0000% 0.0000% 0.0000% 21/08/17    0.0000% 0.0000% 0.0000% 22/08/17    1.0000% 1.0000% 1.0000% 23/08/17    0.0000% 0.0000% 0.0000% 24/08/17    1.9417% 0.9709% 0.9709% 25/08/17    1.8692% 0.9346% 0.9346% 

and trying following dataframe output:

                      df2                              b       c 20/08/17    0.0000% 0.0000% 0.0000% 21/08/17    0.0000% 0.0000% 0.0000% 22/08/17    1.0000% 1.0000% 1.0000% 23/08/17    1.0000% 1.0000% 1.0000% 24/08/17    2.9806% 2.0097% 2.0097% 25/08/17    4.9612% 3.0194% 3.0194% 

where value

df2['a'][1]=df2['a'][0]*(1+df1.sum(axis=1))+df1['a'][1] 

i apply function whole dataframe.

could please me on this?

this should work expected:

df2 = df.copy() in range(df3.index.size):     if not i:         continue     df2.iloc[i] = (df2.iloc[i - 1] * (1 + df.iloc[i].sum())) + df.iloc[i] 

you mentioned in comment don't want "loop through it", can't figure how same without for loop. main limitation want use data newly computed df2[i - 1] in computation of df2[i].

without requirement (then using existing df[i - 1] compute df2[i]) give df + df.shift().fillna(0).mul(1 + df.sum(axis=1), axis=0), not match formula.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -