Skip to content
Advertisement

Pandas – How to use multiple cols for mapping (without merging)?

I have a dataframe like as below

JavaScript

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

JavaScript

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

Advertisement

Answer

Merge can be used for a lot, so let’s first try to use it:

JavaScript
JavaScript

You can also do this by mapping the index like this:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement