I have a dataframe below and I want to add another column called "CUMULATIVE". To get the value of that column you need to just multiply [DAILY]row(x) * [DAILY]row(x-1). In excel it is pretty simple, because you only need to paste formula "=A2*A1" in the the second row and just drag it down. But it is getting hard for me to repeat it in python. Do you have any ideas how to do it ?
I used the below line but it is not correct, because because it multiplicates with each above rows, instead of with just 2 rows nearby.
df['cumprod'] = df.groupby('TICKER')['MNOZNIK_DZIENNY'].cumprod()
source https://stackoverflow.com/questions/71627582/multiply-row-with-upper-row-in-a-column-of-dataframe-python
Comments
Post a Comment