Skip to content
Advertisement

How to change string based on list in pandas

I have a mapper as follows

JavaScript

and a pandas series as follows

JavaScript

I want to change the gm and mls to the key from the mapper such that the result is as follows

JavaScript

How do I go about doing this?

Advertisement

Answer

First flatten nested list of dict to dictonary with words boundaries and pass to Series.replace:

JavaScript

If need always repalce unit if last part of strings add $ for match end of strings:

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