DataFrame.
nunique
Return number of unique elements in the object.
Excludes NA values by default.
Can only be set to 0 at the moment.
Don’t include NaN in the count.
If False, will use the exact algorithm and return the exact number of unique. If True, it uses the HyperLogLog approximate algorithm, which is significantly faster for large amount of data. Note: This parameter is specific to pandas-on-Spark and is not found in pandas.
Maximum estimation error allowed in the HyperLogLog algorithm. Note: Just like approx this parameter is specific to pandas-on-Spark.
approx
Examples
>>> df = ps.DataFrame({'A': [1, 2, 3], 'B': [np.nan, 3, np.nan]}) >>> df.nunique() A 3 B 1 dtype: int64
>>> df.nunique(dropna=False) A 3 B 2 dtype: int64
On big data, we recommend using the approximate algorithm to speed up this function. The result will be very close to the exact unique count.
>>> df.nunique(approx=True) A 3 B 1 dtype: int64