
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine If Two Index Objects with Opposite Orders Are Equal in Python Pandas
To determine if two Index objects with opposite orders are equal or not, use the equals() method.
At first, import the required libraries −
import pandas as pd
Creating Pandas index1 and index2 −
index1 = pd.Index([15, 25, 35, 45, 55, 65, 75, 85, 95]) index2 = pd.Index([95, 85, 75, 65, 55, 45, 35, 25, 15])
Display the index1 and index2 −
print("Pandas Index1...\n",index1) print("Pandas Index2...\n",index2)
Check whether two index objects with opposite order equal or not −
print("\nAre two Index objects with opposite order equal?" "\n",index1.equals(index2))
Example
Following is the code −
import pandas as pd # Creating Pandas index1 and index2 index1 = pd.Index([15, 25, 35, 45, 55, 65, 75, 85, 95]) index2 = pd.Index([95, 85, 75, 65, 55, 45, 35, 25, 15]) # Display the index1 and index2 print("Pandas Index1...\n",index1) print("Pandas Index2...\n",index2) print("\nAre two Index objects with opposite order equal?" "\n",index1.equals(index2))
Output
This will produce the following code −
Pandas Index1... Int64Index([15, 25, 35, 45, 55, 65, 75, 85, 95], dtype='int64') Pandas Index2... Int64Index([95, 85, 75, 65, 55, 45, 35, 25, 15], dtype='int64') Are two Index objects with opposite order equal? False
Advertisements