Pandas DataFrame equals() Method
Example
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)
print(df1.equals(df2))
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.
Syntax
dataframe.duplicated(subset, keep)
Parameters
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.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.