Python | Pandas Series.equals()
Last Updated :
13 Feb, 2019
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index.
Pandas Series.equals()
function test whether two objects contain the same elements. This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements.
Syntax: Series.equals(other)
Parameter :
other : The other Series or DataFrame to be compared with the first.
Returns : True if all elements are the same in both objects, False otherwise.
Example #1: Use Series.equals()
function to check whether the underlying data in the two given series objects are same or not.
import pandas as pd
sr1 = pd.Series([ 80 , 25 , 3 , 25 , 24 , 6 ])
sr2 = pd.Series([ 80 , 25 , 3 , 80 , 24 , 25 ])
index_ = [ 'Coca Cola' , 'Sprite' , 'Coke' , 'Fanta' , 'Dew' , 'ThumbsUp' ]
sr1.index = index_
sr2.index = index_
print (sr1)
print (sr2)
|
Output :
Now we will use Series.equals()
function to check if the underlying data in the two given series objects are same or not.
result = sr1.equals(other = sr2)
print (result)
|
Output :
As we can see in the output, the Series.equals()
function has returned False
indicating the element in the two given series objects are not same.
Example #2: Use Series.equals()
function to check whether the underlying data in the two given series objects are same or not.
import pandas as pd
sr1 = pd.Series([ 80 , 25 , 3 , 25 , 24 , 6 ])
sr2 = pd.Series([ 80 , 25 , 3 , 25 , 24 , 6 ])
index_ = [ 'Coca Cola' , 'Sprite' , 'Coke' , 'Fanta' , 'Dew' , 'ThumbsUp' ]
sr1.index = index_
sr2.index = index_
print (sr1)
print (sr2)
|
Output :
Now we will use Series.equals()
function to check if the underlying data in the two given series objects are same or not.
result = sr1.equals(other = sr2)
print (result)
|
Output :
As we can see in the output, the Series.equals()
function has returned True
indicating the element in the two given series objects are same.
Share your thoughts in the comments
Please Login to comment...