title: Groupby and count() on dataframe having two categorical variables
body: <p>I have a dataset, which I need to groupby() and find the count of each unique combination.</p>
  
  <pre><code>    body-style        make
  0  convertible  alfa-romeo
  1  convertible  alfa-romeo
  2    hatchback  alfa-romeo
  3        sedan        audi
  4        sedan        audi
  </code></pre>
  
  <p>My need is to produce an output as shown below:</p>
  
  <pre><code>             make   body-style   count
  0     alfa-romero  convertible       2
  1     alfa-romero    hatchback       1
  2            audi    sedan           2
  </code></pre>
  
  <p>Tried the below code:</p>
  
  <pre><code>body = pd.DataFrame({'make':['alfa-romeo','alfa-romeo','alfa-romeo','audi','audi'], 'body-style':['convertible','convertible','hatchback','sedan','sedan']})
  
  body.groupby(by=['make','body-style'], as_index=False).count()
  </code></pre>
  
  <p>This aggregation throws up "<em>list index out of range</em>" error. However, when I remove either of the columns from groupby clause, it is able to give me counts grouped by the remaining column. </p>
  
  <p>If I remove <em>as_index=False</em>, there is no error, but the resultant object will have both columns - <em>make</em> and <em>body-style</em> as part of the index and there won'nt be any count data.</p>
  
  <p>I can add another column to the datframe, fill it with 1s and take a <code>sum()</code> instead of <code>count()</code> on the groupby. But would like to know if there is a cleaner way to do this.</p>