Friday, February 6, 2026
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
32490 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6931 POSTS0 COMMENTS