Last active
August 3, 2021 07:43
-
-
Save konstantinstadler/a8c1a651aeda5c67c4910325b8a9b466 to your computer and use it in GitHub Desktop.
converting exiobase 2 letter RoW codes to 3 letters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import country_converter | |
import pandas as pd | |
custom_mapping = pd.DataFrame.from_dict( | |
{ | |
"name_short": ["Africa", "Latin"], | |
"name_official": ["RoW Africa", "RoW Latin America"], | |
"regex": ["restafrica", "restlatin"], | |
"ISO2": ["WA", "WL"], | |
"ISO3": ["WAL", "WLA"], | |
} | |
) | |
countries_to_convert = ["AT", "DE", "US", "FR", "WA", "WL"] | |
coco = country_converter.CountryConverter(additional_data=custom_mapping) | |
new_country_class = coco.convert(countries_to_convert, src="ISO2", to="ISO3") | |
# and back again | |
return_country_class = coco.convert(new_country_class, src="ISO3", to="ISO2") | |
countries_to_convert == return_country_class | |
# TRUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment