I have two columns, column A and column B. From the 2nd rows to the last I want to subtract previous row of column B with current row of column A and store in Column B only. How can I achieve this? I tried by this link but its still not working. Please help
Asked
Active
Viewed 63 times
1 Answers
0
Here is how you can achieve it:
import pandas as pd
df = pd.DataFrame({'A':np.random.randint(1,20,5),
'B':np.random.randint(1,20,5)})
df['B'] = df.A - df.B.shift(1)
Output:

quest
- 3,576
- 2
- 16
- 26