Count number of distinct elements in specified axis.
Return Series with number of distinct elements. Can ignore NaN values.
The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.
Don’t include NaN in the counts.
See also
Series.nuniqueMethod nunique for Series.
DataFrame.countCount non-NA cells for each column or row.
Examples
>>> df = pd.DataFrame({'A': [4, 5, 6], 'B': [4, 1, 1]})
>>> df.nunique()
A 3
B 2
dtype: int64
>>> df.nunique(axis=1)
0 1
1 2
2 2
dtype: int64
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.DataFrame.nunique.html