Python | Pandas Index.equals()
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.equals()
function determine if two Index objects contains the same elements. If they contain the same elements then the function returns True
else the function returns False
indicating the values contained in both the Indexes are different.
Syntax: Index.equals(other)
Parameters :
Other : index
Returns : boolean value
Example #1: Use Index.equals()
function to check if two Indexes contain same elements
import pandas as pd
idx1 = pd.Index([ 'Labrador' , 'Beagle' , 'Labrador' , 'Lhasa' , 'Husky' , 'Beagle' ])
idx2 = pd.Index([ 'Labrador' , 'Beagle' , 'Pug' , 'Lhasa' , 'Husky' , 'Pitbull' ])
print (idx1, "\n" , idx2)
|
Output :
Let’s check if the two Indexes are equal or not.
Output :
As we can see in the output, the Index.equals()
function has returned False
indicating that the Indexes are not equal.
Example #2: Use Index.equals()
function to check the equality of two Indexes.
import pandas as pd
idx1 = pd.Index([ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' ,
'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ])
idx2 = pd.Index([ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' ,
'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ])
print (idx1, "\n" , idx2)
|
Output :
Let’s check if the two Indices are equal to each other or not.
Output :
The function has returned True
indicating that both the Indexes are equal to each other.
Last Updated :
16 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...