I have the following sample of the Dataframe (population rows 100k+):
In:
official delta
0 0.000201567
0 0.000194400
0 0.000151906
62.94957331 0.000144387
64.06471633 0.000125152
64.51335098 0.000133459
64.4101024 0.000120795
0 0.000146456
but receive the following output:
official delta result
0 0.000201567 0
0 0.0001944 0
0 0.000151906 0
62.94957331 0.000144387 0
64.06471633 0.000125152 0
64.51335098 0.000133459 0
64.4101024 0.000120795 0
0 0.000146456 0
Desired solution:
official delta result
0 0.000201567 0
0 0.0001944 0
0 0.000151906 0
62.94957331 0.000144387 62.94957331
64.06471633 0.000125152 64.06471633
64.51335098 0.000133459 64.51335098
64.4101024 0.000120795 64.4101024
0 0.000146456 63.76600137
I tried the following code although it seems that it does not work correctly. I do not understand why it gives a fault result. When I execute it in a demo dataframe, everything is fine.
The code should pick up the 'official' element when mask is True otherwise multiply its previous element with 0.99 . The issue here is that when the mask is True, the code does not pick the 'official' element.
mask = (df['official']<51) & (df['delta']>0)
df['result'] = df['official'].where(mask,0.99).groupby(~mask.cumsum()).cumprod()