Reputation: 372
i have 2 dataframe as below:
student_name student_id
1 may 0000
2 june 1111
3 july 2222
member_id member_name school_name
1 A0 april MIT
2 B0 may NIT
3 C0 june LIT
i want to join the 2 dataframe in a way to produce result as below.
student_name student_id member_id member_name school_name
may 0000 B0 may NIT
june 1111 C0 june LIT
i am think in sql way where student_name = member_name. but i hardly able to do it in pandas.
i have try pandas merge which can base on one same name column. can you teach me a simple method to make the required results.
thank you.
Upvotes: 3
Views: 6969
Reputation: 393933
Use merge
and pass the columns to merge on for left_param
and right_param
respectively:
In [27]:
df.merge(df1, left_on='student_name', right_on='member_name')
Out[27]:
student_name student_id member_id member_name school_name
0 may 0 B0 may NIT
1 june 1111 C0 june LIT
Upvotes: 9