def nunique(self, dropna=True):
obj = self._selected_obj<EOL>def groupby_series(obj, col=None):<EOL><INDENT>return SeriesGroupBy(obj,<EOL>selection=col,<EOL>grouper=self.grouper).nunique(dropna=dropna)<EOL><DEDENT>if isinstance(obj, Series):<EOL><INDENT>results = groupby_series(obj)<EOL><DEDENT>else:<EOL><INDENT>from pandas.core.reshape.concat import concat<EOL>results = [groupby_series(obj[col], col) for col in obj.columns]<EOL>results = concat(results, axis=<NUM_LIT:1>)<EOL>results.columns.names = obj.columns.names<EOL><DEDENT>if not self.as_index:<EOL><INDENT>results.index = ibase.default_index(len(results))<EOL><DEDENT>return results<EOL>
Return DataFrame with number of distinct observations per group for
each column.

.. versionadded:: 0.20.0

Parameters
----------
dropna : boolean, default True
    Don't include NaN in the counts.

Returns
-------
nunique: DataFrame

Examples
--------
>>> df = pd.DataFrame({'id': ['spam', 'egg', 'egg', 'spam',
...                           'ham', 'ham'],
...                    'value1': [1, 5, 5, 2, 5, 5],
...                    'value2': list('abbaxy')})
>>> df
     id  value1 value2
0  spam       1      a
1   egg       5      b
2   egg       5      b
3  spam       2      a
4   ham       5      x
5   ham       5      y

>>> df.groupby('id').nunique()
    id  value1  value2
id
egg    1       1       1
ham    1       1       2
spam   1       2       1

Check for rows with the same id but conflicting values:

>>> df.groupby('id').filter(lambda g: (g.nunique() > 1).any())
     id  value1 value2
0  spam       1      a
3  spam       2      a
4   ham       5      x
5   ham       5      y