I have a dataframe with statistical data that is cumulated with each new row. Every day a new row is added. Now I want to iterate over my column so that each row (starting from last) is substracted from the row above. The new value should be put into a new column. This is how my dataframe looks and the values in the column 'diff' are my desired outcome:
time In diff
0 2017-06-26 7.086
1 2017-06-27 8.086 1
2 2017-06-28 10.200 2.114
this is what I came up with:
for x in df['In']:
df['diff'] = df.iloc[-1] - df.iloc[-2]
but thats not it. How do I start the loop from the last row and how do I make the iloc more dynamic? Can someone help? thank you!