I need to merge two data frames. To make sure that the rows are unique I need to verify that "Name" and "Age" are BOTH matched before merging. I am using the combination as a primary key. Here is my code:
df = pd.merge(df, df1[['Name', 'Age', 'Date']], left_on=['Name', 'Age'], right_on=['Name', 'Age'], how='left')
When I use multiple keys ("Name" and "Age") is this an "And" or "OR" match. I want it only to merge if both "Name" and "Age" match, not if only "Name" matches or "Age" matches. I can't seem to find this in the documentation and I am getting some mixed results.
Update: I do need to do a LEFT join for data reasons. The RIGHT table is a subset of the data I need while I need to keep all data on the LEFT. The key concept is to only merge from the RIGHT the data that matches both "Name" and "Age".
inner
join. Theleft
join keeps all the keys of the left DataFrame and only the matching keys of the right DataFrame – Shivam Roy