Skip to content
Advertisement

Retain strings in a column using a dictionary’s value

I want to retain the string with the largest value based on a dictionary’s key and value. Any suggestion to how to do it effectively?

JavaScript

Expected output:

JavaScript

Advertisement

Answer

One way it to use apply with max and fruit_dict.get as key:

JavaScript

or, if you expect some names to be missing from the dictionary:

JavaScript

output:

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