title: pandas - how to get last n groups of a groupby object and combine them as a dataframe
body: <p>How to get last 'n' groups after <code>df.groupby()</code> and combine them as a dataframe. </p>
  
  <pre><code>data = pd.read_sql_query(sql=sqlstr, con=sql_conn, index_col='SampleTime')
  grouped = data.groupby(data.index.date,sort=False)
  </code></pre>
  
  <p>After doing <code>grouped.ngroups</code> i am getting total number of groups 277. I want to combine last 12 groups and generate a dataframe.</p>