Skip to content

Instantly share code, notes, and snippets.

@konstantinstadler
Last active August 3, 2021 07:43
Show Gist options
  • Save konstantinstadler/a8c1a651aeda5c67c4910325b8a9b466 to your computer and use it in GitHub Desktop.
Save konstantinstadler/a8c1a651aeda5c67c4910325b8a9b466 to your computer and use it in GitHub Desktop.
converting exiobase 2 letter RoW codes to 3 letters
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