python - Pandas: Replace full match string from dictionary -
this question has answer here:
- checking whole string regex 5 answers
i'm using dictionary replace of entries in data frame:
dict1 = { "republic of korea": "south korea", "united states of america": "united states", "united kingdom of great britain , northern ireland": "united kingdom", "china, hong kong special administrative region": "hong kong" }
using df.replace()
accomplishes work:
energy['country'] = energy['country'].replace(dict1, regex=true)
however, realized function replacing every string match , want limit replace function full string matches i'm getting unwanted replacings like:
"democratic people's republic of korea" miss-cleaned "democratic people's south korea"
i tried use regex in dictionary seems not work.
any idea? in advance.
remove regex=true
specify full replacement.
Comments
Post a Comment