How to get the delta value of a row using pandas dataframe

I got a dataframe combined with index = datetime

andcolumn = {'currentprice'}

index currentPrice 2015-03-26 10:09:01 75.75 2015-03-26 10:11:57 75.70

Now I want to get the delta value for every 3 minutes (as an example), I can get the data tactics like this:

index delta 2015-03-26 10:09:01 -0.05 2015-03-26 10:11:57 0.10 ...

What should I do?

+3


source to share


1 answer


To expand on the answer given in the comments, you can use

df['delta'] = df.currentPrice.diff().shift(-1)

      



to get the difference between the price on one line and the next. However, if you are really interested in finding the difference between time periods divided by 3 minutes and not 2m56s in your data, you will need to reprogram your timers using the resample method as described here: http://pandas.pydata.org/ pandas-docs / dev / timeseries.html

+3


source







All Articles