title: Python Pandas Dynamically Create a Dataframe
body: <p>The code below will generate the desired output in <strong>ONE</strong> dataframe, however, I would like to dynamically create data frames in a FOR loop then assign the shifted value to that data frame.  Example, data frame df_lag_12 would only contain column1_t12 and column2_12.  Any ideas would be greatly appreciated.  I attempted to dynamically create 12 dataframes using the EXEC statement, google searching seems to state this is poor practice.</p>
  
  <pre><code>import pandas as pd
  list1=list(range(0,20))
  list2=list(range(19,-1,-1))
  d={'column1':list(range(0,20)),
     'column2':list(range(19,-1,-1))}
  df=pd.DataFrame(d)
  df_lags=pd.DataFrame()
  for col in df.columns:
      for i in range(12,0,-1):
          df_lags[col+'_t'+str(i)]=df[col].shift(i)
      df_lags[col]=df[col].values  
  print(df_lags)
  for df in (range(12,0,-1)):
      exec('model_data_lag_'+str(df)+'=pd.DataFrame()')
  </code></pre>
  
  <p><strong>Desired output for dymanically created dataframe DF_LAGS_12:</strong></p>
  
  <pre><code>var_list=['column1_t12','column2_t12']
  df_lags_12=df_lags[var_list]  
  print(df_lags_12)
  </code></pre>