Python | Pandas Series.equals()

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the first Series
sr1 = pd.Series([80, 25, 3, 25, 24, 6])
  
# Creating the second Series
sr2 = pd.Series([80, 25, 3, 80, 24, 25])
  
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
  
# set the first series index
sr1.index = index_
  
# set the second series index
sr2.index = index_
  
# Print the first series
print(sr1)
  
# Print the second series
print(sr2)

chevron_right


Output :

Now we will use Series.equals() function to check if the underlying data in the two given series objects are same or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

# check for equality
result = sr1.equals(other = sr2)
  
# Print the result
print(result)

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the first Series
sr1 = pd.Series([80, 25, 3, 25, 24, 6])
  
# Creating the second Series
sr2 = pd.Series([80, 25, 3, 25, 24, 6])
  
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
  
# set the first series index
sr1.index = index_
  
# set the second series index
sr2.index = index_
  
# Print the first series
print(sr1)
  
# Print the second series
print(sr2)

chevron_right


Output :

Now we will use Series.equals() function to check if the underlying data in the two given series objects are same or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

# check for equality
result = sr1.equals(other = sr2)
  
# Print the result
print(result)

chevron_right


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.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.