[Solved] How to find profit or loss percentage from consecutive rows [closed]


df = pd.DataFrame()
df['Date'] = ['2017-05-20', '2017-05-20', '2017-05-20']
df['Price'] = [50, 60, 45]
df['Prof/Loss'] = (df['Price'] / df['Price'].shift())*100 - 100

First, I think your math for calculating the Loss/Profit was wrong, I hope I fixed that for you.

Second, you can use the .shift() method to get the previous row, use .shift(-1) to get the next row.

2

solved How to find profit or loss percentage from consecutive rows [closed]