I've this data set:
data = {
'index': [4, 17, 24, 36, 42],
'High': [805.000000, 1094.939941, 1243.489990, 1201.949951, 1172.839966],
}
And I would like to get a slope, like:
test = pd.DataFrame(data)
for i in range(len(test)):
test.loc[:,'slope'] = (test.loc[i+1,'High'] - test.loc[i,'High']) / (test.loc[i+1,'index'] - test.loc[i,'index'])
print(test)
Seems that I'm going out of the boundaries of the loop, but how can I code this in order to get the first row blank and fill the next?
If I do the same code without the +1 and use i instead it works, gives a 0/0 (Nan), but works.
The expected output should be:
