- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the basic operation of the series.equals() method in pandas?
The basic operation of the series.equals() method in the pandas constructor is used to test whether the elements in two series objects are the same or not, and it also compares the shape of the two series object.
The equals() method is very similar to the pandas series.eq() method but the difference is it will return a boolean value as a result, whereas the eq() method returns a series object with boolean values.
The output boolean value True indicates the elements in two series objects are the same. And it indicates False for unequal elements in series objects.
Example 1
In the following example, we will see how the equals() method performs the comparison operation on elements of two series objects.
# importing pandas package import pandas as pd # create pandas Series1 series1 = pd.Series([34, 12, 21, 65, 89]) print("First series object:",series1) # create pandas Series2 series2 = pd.Series([34, 21, 89, 65, 12]) print("second series object:",series2) result = series1.equals(series2) print("Result :", result)
Explanation
So initially, we have created two pandas Series objects with the same elements but the positions are changed.
After successfully creating the two series objects we have applied the equals() method.
Output
The output is given below −
First series object: 0 34 1 12 2 21 3 65 4 89 dtype: int64 Second series object: 0 34 1 21 2 89 3 65 4 12 dtype: int64 Result: False
In the above output block, we can see both input series objects series1, series2, and output of the equals() method. Here, The equals() method returns False which indicates the element in the two given series objects are not the same.
Example 2
In the following example, we will see how the equals() method works for two series objects with the same data but the data types of index labels are different.
# importing pandas package import pandas as pd # create pandas Series1 series1 = pd.Series([78, 22, 12]) print("First series object:",series1) # create pandas Series2 series2 = pd.Series([78, 22, 12], index=[0.0, 1.0, 2.0]) print("second series object:",series2) result = series1.equals(series2) print("Result :", result)
Output
The output is given below −
First series object: 0 78 1 22 2 12 dtype: int64 Second series object: 0.0 78 1.0 22 2.0 12 dtype: int64 Result: True
For the equals() method the data type of elements should be the same. But the data type of index labels no need to have the same dtype. That’s why the equals() method returns True for the following example.
- Related Articles
- What is the basic operation of the series.eq() method in pandas?
- What is the basic operation of pandas Series.factorize() function?
- How does the pandas series.equals() method handle the null values?
- What is the basic method of attribute subset selection?
- What is the use of the series.duplicated() method in pandas?
- What is the use of series.describe method in Pandas?
- What is the TFTP Operation?
- What is the full form of BASIC ?
- What does the add() method do in the pandas series?
- What does the align() method do in the pandas series?
- What does the any() method do in the pandas series?
- What does the apply() method do in the pandas series?
- What is the colour of phynosphtaline in basic solution?
- What does the pandas series.filter() method do?
- What does count method do in the pandas series?
