![]() |
VOOZH | about |
Here, we can count the unique values in Pandas groupby object using different methods. This article depicts how the count of unique values of some attribute in a data frame can be retrieved using Pandas.
The Pandas dataframe.nunique() function returns a series with the specified axis's total number of unique observations. The total number of distinct observations over the index axis is discovered if we set the value of the axis to 0.
Output:
Col_1 a 2 b 2 c 1 d 1 Name: Col_2, dtype: int64
Functions Used:
Example 1:
In the output, you will find that the elements present in col_1 counted the unique element present in that column, i.e, a is present 2 times.
Output:
Example 2:
In the output, you will find that the elements present in col_2 counted the unique element present in that column, i.e,3 is present 2 times.
Output: