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.
import pandas as pd
idx = pd.Index([ 'Harry' , 'Mike' , 'Arther' , 'Nick' ,
'Harry' , 'Arther' ], name = 'Student' )
print (idx)
|
Output :
Let’s find all the unique values in the Index.
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
import pandas as pd
idx = pd.Index([ 21 , 10 , 30 , 40 , 50 , 10 , 50 ])
print (idx)
|
Output :
Let’s find all the unique values in the index
Output :
The function has returned a new index that contains all of the unique values in the original index.
Last Updated :
24 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...