I have a list of prices where I am trying to calculate the change in percentage of each number. I calculated the differences with
prices = [30.4, 32.5, 31.7, 31.2, 32.7, 34.1, 35.8, 37.8, 36.3, 36.3, 35.6]
def f():
for i in range(len(prices)):
print(prices[i]-prices[i-1])
Which returns the differences like
2.1
-0.8
-0.5
...
I know the change in percentage would be ((i-(i-1))/(i-1) *100, but I don't know how to incorporate that into the script. Any help would be much appreciated.