- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Python Pandas – Check if two Dataframes are exactly same
The equals() function is used to check if two dataframes are exactly same. At first, let us create DataFrame1 with two columns −
dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )
Create DataFrame2 with two columns −
dataFrame2 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Mercedes', 'Jaguar'], "Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000] } )
To check for equality, use the equals() method −
dataFrame1.equals(dataFrame2)
Example
Following is the code −
import pandas as pd # Create DataFrame1 dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } ) print"DataFrame1 ...\n",dataFrame1 # Create DataFrame2 dataFrame2 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Mercedes', 'Jaguar'], "Reg_Price": [7000, 1500, 5000, 8000, 9000, 6000] } ) print"\nDataFrame2 ...\n",dataFrame2 # check for equality print"\nAre both the DataFrames equal? ",dataFrame1.equals(dataFrame2)
Output
This will produce the following output −
DataFrame1 ... Car Units 0 BMW 100 1 Lexus 150 2 Audi 110 3 Mustang 80 4 Bentley 110 5 Jaguar 90 DataFrame2 ... Car Reg_Price 0 BMW 7000 1 Lexus 1500 2 Audi 5000 3 Mustang 8000 4 Mercedes 9000 5 Jaguar 6000 Are both the DataFrames equal? False
- Related Articles
- Python Pandas – Check if two Dataframes are exactly same
- Python Pandas – Check if any specific column of two DataFrames are equal or not
- How to check if two vectors are exactly same in R?
- Python Pandas – Find the Difference between two Dataframes
- Program to check two trees are exactly same based on their structure and values in Python
- Python - Fetch columns between two Pandas DataFrames by Intersection
- Python - How to Concatenate more than two Pandas DataFrames?
- Python Pandas - Finding the uncommon rows between two DataFrames
- Check if sum of divisors of two numbers are same in Python
- How to compare two DataFrames in Python Pandas with missing values
- Python – Get the Columns Shared by Two Pandas DataFrames using Numpy
- Python Pandas – Fetch the Common rows between two DataFrames with concat()
- Python - How to Concatenate Two or More Pandas DataFrames along columns?
- Python - How to Concatenate Two or More Pandas DataFrames along rows?
- Python Pandas – Find the common rows between two DataFrames with merge()
- How to append two DataFrames in Pandas?

Advertisements