In [1]:
import pandas as pd
In [22]:
# import the pandas library
import pandas as pd
left1 = pd.DataFrame({
'id':[1,2,3,4,5],
'Name': ['Alex', 'Amy', 'Allen', 'Alice', 'Ayoung'],
'subject_id':['sub1','sub2','sub4','sub6','sub5']})
right1 = pd.DataFrame(
{'id':[1,2,3,4,5],
'Name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'],
'subject_id':['sub2','sub4','sub3','sub6','sub5']})
print (left)
print (right)
In [13]:
#left
In [14]:
#right
In [23]:
pd.merge(left1,right1,on='id')
Out[23]:
In [24]:
pd.merge(left1,right1,on=['id','subject_id'])
Out[24]:
In [25]:
pd.merge(left1, right1, on='subject_id', how='left')
Out[25]:
In [19]:
pd.merge(left, right, on='subject_id', how='right')
Out[19]:
In [26]:
pd.merge(left, right, how='outer', on='subject_id',sort=True)
Out[26]:
In [21]:
pd.merge(left, right, on='subject_id', how='inner')
Out[21]:
No comments:
Post a Comment