python - Lagging and differencing variables -


i tying 2 things:

  1. lag variables in python; ,
  2. difference them.

i tried using tail method lag, seems inefficient way so. var basic time series variable or nx1 vector.

var-var.tail(len(var)-1) 

can please give me guidance?

you can use pandas series functionality

>>> import pandas pd >>> t = pd.series([1,2,3,4,5]) >>> t 0    1 1    2 2    3 3    4 4    5 dtype: int64 >>> t.shift(1) 0   nan 1     1 2     2 3     3 4     4 dtype: float64 >>> t-t.shift(1) 0   nan 1     1 2     1 3     1 4     1 dtype: float64 

see more in description of time series functionality


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -