python - Lagging and differencing variables -
i tying 2 things:
- lag variables in python; ,
- 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
Post a Comment