given this Dataframe :
import pandas as pd
import numpy as np
data = {'column1': [True,False, False, True, True],
'column2' : [np.nan,0.21, np.nan, 0.2222, np.nan],
'column3': [1000, 0, 0, 0, 0 ]}
df = pd.DataFrame.from_dict(data)
print(df)
column1 column2 column3
0 True NaN 1000
1 False 0.2100 0
2 False NaN 0
3 True 0.2222 0
4 True NaN 0
How can I multiply the result from column2 with the previous value of column3 when the column2 row isn't a NaN otherwise just return the previous value of column3 ?
The results should be something like this :
column1 column2 column3
0 True NaN 1000
1 False 0.2100 210
2 False NaN 210
3 True 0.2222 46.662
4 True NaN 46.662
I've been browsing through similar questions but I just can't get my head around it ..
I'd appreciate your input :)