You are viewing documentation about an older version (1.18.0). View latest version

modin.pandas.DataFrame.nunique¶

DataFrame.nunique(axis: int = 0, dropna: bool = True) → Series[source]¶

Count number of distinct elements in specified axis.

Return Series with number of distinct elements. Can ignore NaN values. Snowpark pandas API does not distinguish between NaN values and treats them all as the same.

Parameters:
  • axis ({0 or 'index', 1 or 'columns'}, default 0) – The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.

  • dropna (bool, default True) – Don’t include NaN in the counts.

Return type:

Series

Examples

>>> import snowflake.snowpark.modin.pandas as pd
>>> df = pd.DataFrame({'A': [4, 5, 6], 'B': [4, 1, 1]})
>>> df.nunique()
A    3
B    2
dtype: int8
Copy
>>> df.nunique(axis=1)
0    1
1    2
2    2
dtype: int8
Copy
>>> df = pd.DataFrame({'A': [None, pd.NA, None], 'B': [1, 2, 1]})
>>> df.nunique()
A    0
B    2
dtype: int8
Copy
>>> df.nunique(dropna=False)
A    1
B    2
dtype: int8
Copy

Note

See pandas API documentation for pandas.DataFrame for more.