Whenever there is a matching column/key between dataframe dfa and dfb, I want to change the name of the country in dataframe a with match in dataframe b.
dfa data:
Country
Bolivia
Bosnia-Herzegovina
dfb data: (full and correct data)
ISO Country
BOL 'Bolivia, Plurinational State of
BIH Bosnia and Herzegovina
First I tried to merge the tables dfa and dfb based on country and any then do a string replace based on like but for some unknown reason any strings with commas are not matching still
dfa.ix[dfa.Country=='Bolivia', 'Country'] = 'Bolivia, Plurinational State of'
This works in that the replacement happens, but when the data is compared to the second table which contains this exact string, it doesn't see it as equal so does not update the null when I merge the tables.
dfab_merge_null = dfab_merge.loc[dfab_merge['ISO'].isnull()]
dfab_merge_null.Country.unique()
array(['Azores', 'Bolivia, Plurinational State of', 'Canary Is', 'Iran, Islamic Republic of', "Korea, Democratic People's Republic of", 'Korea, Republic of', 'Macedonia, The Former Yugoslav Republic of', 'Micronesia\, Federated States of', 'Moldova, Republic of', 'Palestine (West Bank)', 'St Kitts and Nevis'... etc
dfa does not contain the ISO column, which is what I want to add ultimately.
dfb contains the ISO that I'm trying to transfer into dfa based on loosely matching string names in Country between the two tables.
I'm unsure what other method to try to update. I've been stuck on this for over a day and would appreciate any help. Thanks!