Thursday, September 4, 2025
HomeLanguagesPython | Pandas Index.unique()

Python | Pandas Index.unique()

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.

Pandas Index.unique() function return unique values in the index. Uniques are returned in order of appearance, this does NOT sort.

Syntax: Index.unique(level=None)

Parameters :
level : Only return values from specified level (for MultiIndex)

Returns : Index without duplicates

Example #1: Use Index.unique() function to return unique values in the index.




# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index(['Harry', 'Mike', 'Arther', 'Nick',
                'Harry', 'Arther'], name ='Student')
  
# Print the Index
print(idx)


Output :

Let’s find all the unique values in the Index.




# find unique values in the index
idx.unique()


Output :

The function has returned a new index having all the unique values of the original index.
 
Example #2: Use Index.unique() function to find the unique values in the index




# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index([21, 10, 30, 40, 50, 10, 50])
  
# Print the Index
print(idx)


Output :

Let’s find all the unique values in the index




# for finding the unique values in the index
idx.unique()


Output :

The function has returned a new index that contains all of the unique values in the original index.

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS