I have a dataframe like as below
data_df = pd.DataFrame({'p_id': ['abc@gmail.com','abc@gmail.com','abc@gmail.com','ace@gmail.com','ace@gmail.com','pqr@gmail.com','pqr@gmail.com'],
'company': ['a','b','c','d','e','f','g'],
'dept_access':['a1','a1','a1','a1','a2','a2','a2']})
key_df = pd.DataFrame({'p_id': ['abc@gmail.com','xyz@gmail.com','pqr@gmail.com'],
'company': ['a','c','b'],
'location':['UK','USA','KOREA']})
I would like to do the below
a) Attach the location column from key_df to data_df based on two fields - p_id and company
So, I tried the below
loc = key_df.drop_duplicates(['p_id','company']).set_index(['p_id','company'])['location']
data_df['location'] = data_df[['p_id','company']].map(loc)
But this resulted in error like below
KeyError: "None of [Index(['p_id','company'], dtype='object')] are in the [columns]"
How can I map based on multiple index columns? I don't wish to use merge