How to find out number of unique rows within a pandas groupby object?
<p>I know that we can use .nunique() on a groupby column to find out the unique number of elements in the column like below:</p>

<pre><code>df = pd.DataFrame({'c1':['foo', 'bar', 'foo', 'foo'], 'c2': ['A', 'B', 'A', 'B'], 'c3':[1, 2, 1, 1]})

    c1 c2  c3
0  foo  A   1
1  bar  B   2
2  foo  A   1
3  foo  B   1

df.groupby('c1')['c2'].nunique()

c1
bar    1
foo    2
Name: c2, dtype: int64
</code></pre>

<p>However, now I have a groupby object that contains multiple columns, is there any way to find out the number of unique rows?</p>

<pre><code>df.groupby('c1')['c2', 'c3'].???
</code></pre>

<hr>

<p>Update:
So the end result I want is the number of unique rows within each group that's grouped based on the 'c1' column, such as this:</p>

<pre><code>foo 2
bar 1
</code></pre>

<hr>

<p>Update 2:
Here's a new test dataframe:</p>

<pre><code>df = pd.DataFrame({'c1': ['foo', 'bar', 'foo', 'foo', 'bar'], 'c2': ['A'
, 'B', 'A', 'B', 'A'], 'c3': [1, 2, 1, 1, 1]})
</code></pre>

<p>If need by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.SeriesGroupBy.nunique.html" rel="nofollow"><code>nunique</code></a> concanecated column <code>c2</code> and <code>c3</code>, the easier is use:</p>

<pre><code>df['c'] = df.c2 + df.c3.astype(str)
print (df.groupby('c1')['c'].nunique())
c1
bar    1
foo    2
Name: c, dtype: int64      
</code></pre>

<p>Or <code>groupby</code> by <code>Series</code> <code>c</code> by column <code>df.c1</code>:</p>

<pre><code>c = df.c2.astype(str) + df.c3.astype(str)
print (c.groupby([df.c1]).nunique())
c1
bar    2
foo    2
dtype: int64
</code></pre>

python pandas dataframe group-by