Python | Pandas Series.nunique()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, and makes importing and analyzing data much easier.
While analyzing the data, many times the user wants to see the unique values in a particular column. Pandas
nunique() is used to get a count of unique values.
To download the CSV file used, Click Here.
dropna: Exclude NULL value if True
Return Type: Integer – Number of unique values in a column.
Example #1: Using nunique()
In this example, nunique() method is used to get number of all unique values in Team column.
The output of number of unique values is returned.
Example #2: NULL value Handling
In this example, length of array returned by unique() method is compared to integer returned by nunique() method.
The output is not same in both of the cases as dropna parameter is set to True and hence NULL values were excluded while counting unique values.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course