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:
Pandas – Find the Difference between two Dataframes
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:
Contact Us