How to Get Unique Values in Column of Pandas DataFrame

In this post, we will see how to get Unique Values from a Column in Pandas DataFrame.

Sometimes, You might want to get unique Values from a Column in large Pandas DataFrame.

Here is a sample Employee data which we will use.

NameAgeDepartment
Rohit26Sales
John21HR
Appy34Sales
Smita47Tech
Neha22HR

Using unique() method

You can use Pandas unique() method to get unique Values from a Column in Pandas DataFrame.
Here is an example. We will use unique() method to get unique value from Department column.

Output:

As you can see, we got unique values for Department column.
If you want the result as list, you can use toList() function to convert numpy.ndarray to list.
Change highlight line with below line:

Output:

Using drop_duplicates() method

You can also use drop_duplicates() to get unique values from a column in Pandas DataFrame. Although this method does not obvious as compared to unique one.

Here is an example. We will use drop_duplicates() method to get unique value from Department column.

Output:

As you can see, we got Series as output by using drop_duplicates() method.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *