Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame equals() Method

❮ DataFrame Reference


Check if two DataFrames ar equal:

import pandas as pd

data1 = {
  "name": ["Sally", "Mary", "John", "Mary"],
  "age": [50, 40, 30, 40]
df1 = pd.DataFrame(data)

data2 = {
  "name": ["Sally", "Mary", "John", "Mary"],
  "age": [50, 40, 30, 40]
df2 = pd.DataFrame(data)

Try it Yourself »

Definition and Usage

The duplicated() method compares two DataFrames and returns True if they are equal, in both shape and content, otherwise False.

Use the subset parameter to specify if any columns should not be considered when comparing.


dataframe.duplicated(subset, keep)


The parameters are keyword arguments.

Parameter Value Description
subset column label(s) Optional. A String, or a list, containing any columns to ignore
keep 'first'
Optional, default 'first'. Specifies which duplicate to keep. If False, drop ALL duplicates

Return Value

A Boolean, True if the DataFrames are equal, otherwise False.

❮ DataFrame Reference