Skip to content
Advertisement

Exactly Vlookup functionality in Pandas

I have 2 Dataframes. I excel i would add additional columns to Holdings lets say “S&P Number” and perform Vlookup by taking S&P from Holdings and look in Rating Map then return Number value.

Holdings =

JavaScript

Ratings Map =

JavaScript

Please note that we dont have one key in this situation, if i want to cover all 3 Ratings and go with merge i have to always drop additional column because

JavaScript

Output:

JavaScript

Desired Output without using “drop”:

JavaScript

Final result will contain both “S&P” and “Rating_S&P”) which i have to drop. I was wondering if there is any better way to do that – like vlookup?

Advertisement

Answer

Just use RatingsMap['Fitch'] for right_on and remove 'Fitch' in the initial field. Like below.

JavaScript

Below is what i have done & the output is also shown

JavaScript

My dataframes are named as df & df1 instead of Holdings & Ratingsmap

output

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