Columns are the different fields that contain their particular values when we create a DataFrame. We can perform certain operations on both rows & column values. In this article, we are going to learn how to count unique values in a column.
Unique values are those values that only occur once.
For this purpose, we are going to use a pandas.Series.unique() method inside pandas. This method will remove all the occurrences except the first occurrence,
pandas.Series.unique() Method
This method selects the specified column passed as a parameter inside it and returns the unique values inside it.
Syntax:
Series.unique()
# or
DataFrame['col_name'].unique()
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example:
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer