Here is my Pandas data frame:
prices = pandas.DataFrame([1035.23, 1032.47, 1011.78, 1010.59, 1016.03, 1007.95,
1022.75, 1021.52, 1026.11, 1027.04,
Because operations will do alignment on index, you can convert one of the DataFrames to array:
prices[:-1].values / prices[1:] - 1
or
prices[:-1] / prices[1:].values - 1
depends on what the index of the result you want.
or use shift()
method:
prices.shift(1) / prices - 1
and:
prices / prices.shift(1) - 1