Lag functions

Module for producing lagged versions of pandas DataFrames

Let’s start out by defining a short multivariate time-series:

X = pd.DataFrame([[2,3,4],[5,6,7],[8,8,6],[9,10,3],[11,4,6]]); X
0 1 2
0 2 3 4
1 5 6 7
2 8 8 6
3 9 10 3
4 11 4 6

source

lag

 lag (X:pandas.core.frame.DataFrame, lags:list)

Return a dataframe with specific lags

Type Details
X DataFrame A pandas dataframe with observations as rows and variables as columns
lags list A list with the same number of lists as the number of columns of X containing the desired lagged versions desired for the variable in that column
Returns DataFrame A dataframe with the specified lagged variables of X
lags = [[0,1],[0,2],[0,3]]
lag(X,lags)
0 1 2
t t-1 t t-2 t t-3
3 9 8.0 10 6.0 3 4.0
4 11 9.0 4 8.0 6 7.0

source

lag_uniform

 lag_uniform (X:pandas.core.frame.DataFrame, lag:int)
Type Details
X DataFrame A pandas dataframe with observations as rows and variables as columns
lag int Integer of the maximum lag to include for all variables of X
Returns DataFrame A dataframe with the lagged variables of X
lag_uniform(X,2)
Variable 0 1 2 0 1 2 0 1 2
Time t t t t-1 t-1 t-1 t-2 t-2 t-2
0 8 8 6 5 6 7 2 3 4
1 9 10 3 8 8 6 5 6 7
2 11 4 6 9 10 3 8 8 6