(df, lag=1, extrapolate=1, dropna=True, suffix="t")
return agg
Take in a 2D DataFrame (n_samples by n_features) and create a new DataFrame with lag observations added to it.
    E.g. If lags=2, the previous two observations will be concatenated as inputs to each sample.
    The extrapolate argument can be used to add current (=1) and future observations (>1).
    Samples without enough lags can be retained or dropped using the dropna argument.
    The input DataFrame is assumed to be pre-sorted.
Take in a 2D DataFrame (n_samples by n_features) and create a new DataFrame with lag observations added to it.
    E.g. If lags=2, the previous two observations will be concatenated as inputs to each sample.
    The extrapolate argument can be used to add current (=1) and future observations (>1).
    Samples without enough lags can be retained or dropped using the dropna argument.
    The input DataFrame is assumed to be pre-sorted.
Take in a 2D DataFrame ( n_samples by n_features ) and create a new DataFrame with lag observations added to it . E . g . If lags = 2 the previous two observations will be concatenated as inputs to each sample . The extrapolate argument can be used to add current ( = 1 ) and future observations ( > 1 ) . Samples without enough lags can be retained or dropped using the dropna argument . The input DataFrame is assumed to be pre - sorted .
def add_lags(df, lag=1, extrapolate=1, dropna=True, suffix="t"):
    """
    Take in a 2D DataFrame (n_samples by n_features) and create a new DataFrame with lag observations added to it.
    E.g. If lags=2, the previous two observations will be concatenated as inputs to each sample.
    The extrapolate argument can be used to add current (=1) and future observations (>1).
    Samples without enough lags can be retained or dropped using the dropna argument.
    The input DataFrame is assumed to be pre-sorted.
    """
    
    n_features = df.shape[1]
    
    cols, names = list(), list()
    
    # input sequence (t-n, ... t-1)
    for i in range(lag, 0, -1):
        cols.append(df.shift(i))
        names += ["{0}({1}-{2})".format(df.columns[j], suffix, i) for j in range(n_features)]
    
    # forecast sequence (t, t+1, ... t+n)
    for i in range(0, extrapolate):
        cols.append(df.shift(-i))
        if i == 0:
            names += ["{0}({1})".format(df.columns[j], suffix) for j in range(n_features)]
        else:
            names += ["{0}({1}+{2})".format(df.columns[j], suffix, i) for j in range(n_features)]
    
    # Concatenate the shifted DataFrames
    agg = pd.concat(cols, axis=1)
    # Add the concatenated column names
    agg.columns = names
    
    # drop rows with NaN values
    if dropna:
        agg.dropna(inplace=True)
    
    return agg
def add_lags ( df , lag = 1 , extrapolate = 1 , dropna = True , suffix = "t" ) : n_features = df . shape [ 1 ] cols , names = list ( ) , list ( ) # input sequence (t-n, ... t-1) for i in range ( lag , 0 , - 1 ) : cols . append ( df . shift ( i ) ) names += [ "{0}({1}-{2})" . format ( df . columns [ j ] , suffix , i ) for j in range ( n_features ) ] # forecast sequence (t, t+1, ... t+n) for i in range ( 0 , extrapolate ) : cols . append ( df . shift ( - i ) ) if i == 0 : names += [ "{0}({1})" . format ( df . columns [ j ] , suffix ) for j in range ( n_features ) ] else : names += [ "{0}({1}+{2})" . format ( df . columns [ j ] , suffix , i ) for j in range ( n_features ) ] # Concatenate the shifted DataFrames agg = pd . concat ( cols , axis = 1 ) # Add the concatenated column names agg . columns = names # drop rows with NaN values if dropna : agg . dropna ( inplace = True ) return agg