title: Create new dataframe in pandas with dynamic names also add new column
body: <p>I have a dataframe df </p>
  
  <pre><code> df = pd.DataFrame({'A':['-a',1,'a'], 
                 'B':['a',np.nan,'c'],
                 'ID':[1,2,2],
                  't':[pd.tslib.Timestamp.now(),pd.tslib.Timestamp.now(),
                      np.nan]})
  </code></pre>
  
  <p>Added a new column </p>
  
  <pre><code>df['YearMonth'] = df['t'].map(lambda x: 100*x.year + x.month)
  </code></pre>
  
  <p>Now I want to write a function or macro which will do date comparasion, create a new dataframe also add a new column to dataframe.</p>
  
  <p>I tried like this but seems I am going wrong:</p>
  
  <pre><code>def test(df,ym):
      df_new=df
      if(ym &lt;= df['YearMonth']):
          df_new+"_"+ym=df_new
          return df_new+"_"+ym
      df_new+"_"+ym['new_col']=ym
  </code></pre>
  
  <p>Now when I call test function I want a new dataframe should get created named as <code>df_new_201612</code> and this new dataframe should have one more column, named as <code>new_col</code> that has value of <code>ym</code> for all the rows.</p>
  
  <pre><code>test(df,201612)
  </code></pre>
  
  <p>The output of new dataframe is:</p>
  
  <p><strong>df_new_201612</strong></p>
  
  <pre><code>A   B   ID  t                           YearMonth   new_col
  -a  a   1   2016-12-05 12:37:56.374620  201612      201612 
  1   NaN 2   2016-12-05 12:37:56.374644  201208      201612 
  a   c   2   nat                         nan         201612 
  </code></pre>