title: Converting Groupby Object into DataFrame objects in a loop
body: <p>I have a dataframe <code>df</code> that looks like this</p>
  
  <pre><code>No Country Sex Age Group
  1    Spain   M Young
  2    Norway  F Middle
  3    Mexico  M Elderly
  ...
  </code></pre>
  
  <p>My aim is to group this data based on country first, then do analysis based on sex and age groups, using <code>.value_counts()</code></p>
  
  <p>Thus, I used <code>groupby</code> on this via <code>df2 = df.groupby(df.Country)</code>and looped like this</p>
  
  <pre><code>for d in df2:
      print(type(d))
  </code></pre>
  
  <p>I am getting this output:</p>
  
  <pre><code>&lt;class 'tuple'&gt;
  &lt;class 'tuple'&gt;
  &lt;class 'tuple'&gt;
  ...
  </code></pre>
  
  <p>I wanted to use </p>
  
  <pre><code>for d in df2:
      print(pd.DataFrame(d).Sex.value_counts())
  </code></pre>
  
  <p>but I am getting this error</p>
  
  <pre><code>DataFrame constructor not properly called!
  </code></pre>
  
  <p>I had asked a similar <a href="https://stackoverflow.com/questions/51058073/how-to-group-rows-so-as-to-use-value-counts-on-the-created-groups-with-pandas/51058114?noredirect=1#51058114">question</a> yesterday, but that was limited to a very particular query. What I want to learn is to know how to "group" layers into chunks and then do analysis on those particular chunks.</p>
  
  <p>Thanks!</p>