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><strong>UPDATE:</strong></p>

<pre><code>In [131]: df.groupby(['c1','c2','c3']).size().rename('count').reset_index()[['c1','count']].drop_duplicates(subset=['c1'])
Out[131]:
    c1  count
0  bar      1
1  foo      2
</code></pre>

<p><strong>OLD answer:</strong></p>

<p>IIYC you need this:</p>

<pre><code>In [43]: df.groupby(['c1','c2','c3']).size()
Out[43]:
c1   c2  c3
bar  B   2     1
foo  A   1     2
     B   1     1
dtype: int64
</code></pre>

python pandas dataframe group-by