groupby.DataFrameGroupBy.nunique

DataFrameGroupBy.nunique() pd.DataFrame[source]

Compute the nunique value for each group.

Parameters

numeric_only: {True, False, None} Default is True

Which datatype to be returned - True: Returns all values as float64, NaN/NaT values are removed - None: Returns all values as the same dtype where possible, NaN/NaT are removed - False: Returns all values as the same dtype where possible, NaN/NaT are preserved

Returns

pandas.DataFrame

nunique value for each numeric column of each group

See Also

:pandas_api_docs:`pandas.core.groupby.GroupBy.nunique`

Examples

>>> from tests import OPENSEARCH_TEST_CLIENT
>>> df = oml.DataFrame(
...   OPENSEARCH_TEST_CLIENT, "flights",
...   columns=["AvgTicketPrice", "Cancelled", "dayOfWeek", "DestCountry"]
... )
>>> df.groupby("DestCountry").nunique() 
             AvgTicketPrice  Cancelled  dayOfWeek
DestCountry
AE                       46          2          7
AR                      305          2          7
AT                      377          2          7
AU                      416          2          7
CA                      944          2          7
...                     ...        ...        ...
RU                      739          2          7
SE                      255          2          7
TR                       10          2          5
US                     1987          2          7
ZA                      283          2          7

[32 rows x 3 columns]