code: def sequence_frame(
      df, target, forecast_period=1, leaders=[], lag_period=1
  ):
      r"""Create sequences of lagging and leading values.
  
      Parameters
      ----------
      df : pandas.DataFrame
          The original dataframe.
      target : str
          The target variable for prediction.
      forecast_period : int
          The period for forecasting the target of the analysis.
      leaders : list
          The features that are contemporaneous with the target.
      lag_period : int
          The number of lagged rows for prediction.
  
      Returns
      -------
      new_frame : pandas.DataFrame
          The transformed dataframe with variable sequences.
  
      """
  
      # Set Leaders and Laggards
      le_cols = sorted(leaders)
      le_len = len(le_cols)
      df_cols = sorted(list(set(df.columns) - set(le_cols)))
      df_len = len(df_cols)
  
      # Add lagged columns
      new_cols, new_names = list(), list()
      for i in range(lag_period, 0, -1):
          new_cols.append(df[df_cols].shift(i))
          new_names += [
              "%s[%d]" % (df_cols[j], i) for j in range(df_len)
          ]
  
      # Preserve leader columns
      new_cols.append(df[le_cols])
      new_names += [le_cols[j] for j in range(le_len)]
  
      # Forecast Target(s)
      new_cols.append(
          pd.DataFrame(df[target].shift(1 - forecast_period))
      )
      new_names.append(target)
  
      # Collect all columns into new frame
      new_frame = pd.concat(new_cols, axis=1)
      new_frame.columns = new_names
      return new_frame
  
file_path: AlphaPy/alphapy/frame.py
imports: from alphapy.globals import PSEP, SSEP, USEP
  from alphapy.globals import TAG_ID
  import logging
  import pandas
label_desc: Use image node_id 6 for calling a global function with example usage: sequence_frame(df, target, forecast_period, leaders, lag_period) and returns: new_frame