find difference between two dataframes pandas code example

Example 1: python pandas difference between two data frames

diff_df = pd.merge(df1, df2, how='outer', indicator='Exist')

diff_df = diff_df.loc[diff_df['Exist'] != 'both']

Example 2: findout not common values between two data frames

df = df1.merge(df2, how = 'outer' ,indicator=True).loc[lambda x : x['_merge']=='left_only']
 
df

Example 3: pandas difference between two dataframes

source_df.merge(target_df,how='left',indicator=True).loc[lambda x:x['_merged']!='both']