title: Adding a 'count' column to the result of a groupby in pandas?
body: <p>I think this is a fairly basic question, but I can't seem to find the solution.</p>
  
  <p>I have a pandas dataframe similar to the following:</p>
  
  <pre><code>import pandas as pd
  
  df = pd.DataFrame({'A' : ['x','x','y','z','z'],
                     'B' : ['p','p','q','r','r']})
  df
  </code></pre>
  
  <p>which creates a table like this:</p>
  
  <pre><code>    A   B
  0   x   p
  1   x   p
  2   y   q
  3   z   r
  4   z   r
  </code></pre>
  
  <p>I'm trying to create a table that represents the number of distinct values in that dataframe. So my goal is something like this:</p>
  
  <pre><code>    A   B   c
  0   x   p   2
  1   y   q   1
  2   z   r   2
  </code></pre>
  
  <p>I can't find the correct functions to achieve this, though. I've tried:</p>
  
  <pre><code>df.groupby(['A','B']).agg('count')
  </code></pre>
  
  <p>This produces a table with 3 rows (as expected) but without a 'count' column. I don't know how to add in that count column. Could someone point me in the right direction?</p>