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
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]]
|
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