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':[45,78,44,89,66,49,72]}
df1 = pd.DataFrame(df1,columns= ['Name','score1','score2'])
print("Given Dataframe :
", df1)
# getting Difference
df1['Score_diff'] = df1['score1'] - df1['score2']
print("
Difference of score1 and score2 :
", df1)
# by doing outer, you will get records from both the sides.
f = df1.merge(df2,indicator = True, how='outer').loc[lambda x : x['_merge']!='both']
Out[421]:
A B _merge
1 2 3 left_only
2 3 4 left_only
3 3 4 left_only
left_unique_result = f.loc[lambda x: x['_merge'] == 'left_only']
right_unique_result = f.loc[lambda x: x['_merge'] == 'right_only']
df1.merge(df2,indicator = True, how='left').loc[lambda x : x['_merge']!='both']
Out[421]:
A B _merge
1 2 3 left_only
2 3 4 left_only
3 3 4 left_only