How do I subtract the previous row from the current row in a pandas dataframe and apply it to every row; without using a loop?
you can use pct_change() or/and diff() methods
Demo:
In [138]: df.Close.pct_change() * 100
Out[138]:
0 NaN
1 0.469484
2 0.467290
3 -0.930233
4 0.469484
5 0.467290
6 0.000000
7 -3.255814
8 -3.365385
9 -0.497512
Name: Close, dtype: float64
In [139]: df.Close.diff()
Out[139]:
0 NaN
1 0.125
2 0.125
3 -0.250
4 0.125
5 0.125
6 0.000
7 -0.875
8 -0.875
9 -0.125
Name: Close, dtype: float64
MaxU solutions suits in your case. If you want to perform more complex computations based on your previous rows you should use shift