Pandas - Find the Difference between two Dataframes Last Updated : 16 Mar, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to compare two DataFrames in pandas. First, let's create two DataFrames. Creating two dataframes Python3 import pandas as pd # first dataframe df1 = pd.DataFrame({ 'Age': ['20', '14', '56', '28', '10'], 'Weight': [59, 29, 73, 56, 48]}) display(df1) # second dataframe df2 = pd.DataFrame({ 'Age': ['16', '20', '24', '40', '22'], 'Weight': [55, 59, 73, 85, 56]}) display(df2) Output: Checking If Two Dataframes Are Exactly Same By using equals() function we can directly check if df1 is equal to df2. This function is used to determine if two dataframe objects in consideration are equal or not. Unlike dataframe.eq() method, the result of the operation is a scalar boolean value indicating if the dataframe objects are equal or not. Syntax: DataFrame.equals(df) Example: Python3 df1.equals(df2) Output: False We can also check for a particular column also. Example: Python3 df2['Age'].equals(df1['Age']) Output: FalseFinding the common rows between two DataFrames We can use either merge() function or concat() function. The merge() function serves as the entry point for all standard database join operations between DataFrame objects. Merge function is similar to SQL inner join, we find the common rows between two dataframes. The concat() function does all the heavy lifting of performing concatenation operations along with an axis od Pandas objects while performing optional set logic (union or intersection) of the indexes (if any) on the other axes. Example 1: Using merge function Python3 df = df1.merge(df2, how = 'inner' ,indicator=False) df Output: Example 2: Using concat function We add the second dataframe(df2) below the first dataframe(df1) by using concat function. Then we groupby the new dataframe using columns and then we see which rows have a count greater than 1. These are the common rows. This is how we can use- Python3 df = pd.concat([df1, df2]) df = df.reset_index(drop=True) df_group = df.groupby(list(df.columns)) idx = [x[0] for x in df_group.groups.values() if len(x) > 1] df.reindex(idx) Output: Finding the uncommon rows between two DataFrames We have seen that how we can get the common rows between two dataframes. Now for uncommon rows, we can use concat function with a parameter drop_duplicate. Example: Python3 pd.concat([df1,df2]).drop_duplicates(keep=False) Output: Comment More infoAdvertise with us Next Article Difference of two columns in Pandas dataframe V vanisinghal0201 Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2020 Python-pandas Python pandas-dataFrame +1 More Practice Tags : python Similar Reads Find the Difference Between Two Rows in Pandas Finding the difference between two rows in Pandas typically involves calculating how values in columns change from one row to the next i.e the difference in sales data from past month to current month. This task is especially important in time-series data or datasets where temporal progression, rank 4 min read Difference of two columns in Pandas dataframe Difference of two columns in pandas dataframe in Python is carried out by using following methods : Method #1 : Using â -â operator. Python3 import pandas as pd # Create a DataFrame df1 = { 'Name':['George','Andrea','micheal', 'maggie','Ravi','Xien','Jalpa'], 'score1':[62,47,55,74,32,77,86], 'score2 2 min read Difference of two columns in Pandas dataframe Difference of two columns in pandas dataframe in Python is carried out by using following methods : Method #1 : Using â -â operator. Python3 import pandas as pd # Create a DataFrame df1 = { 'Name':['George','Andrea','micheal', 'maggie','Ravi','Xien','Jalpa'], 'score1':[62,47,55,74,32,77,86], 'score2 2 min read Pandas Dataframe Difference When working with multiple DataFrames, you might want to compute the differences between them, such as identifying rows that are in one DataFrame but not in another. Pandas provides various ways to compute the difference between DataFrames, whether it's comparing rows, columns, or entire DataFrames. 4 min read Distance Calculation Between Points in Different DataFrames Using Pandas We are given two DataFrames in Pandas, each containing coordinates of points. We have to find the distance between corresponding points in these DataFrames in Python. Distance Between Two Points In Two Different Dataframes In PandasLet us see a few different approaches to finding the distance betwee 3 min read Python | Pandas dataframe.diff() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.diff() is used to find the first discrete difference of objects over 2 min read Like