Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consolidate different alternative names of countries, under the official name

Tags:

python-3.x

I'm searching for a list or python packages, to help me unify under one name different names of countries.

For example:

USA, SUA, United States, Unites States of America
Germany, Federal Republic of Germany, Deutschland, Duitsland

I want to consolidate them under the official name, and allocate them iso standard.

like image 892
user3541631 Avatar asked Sep 13 '25 05:09

user3541631


1 Answers

This package, country_converter, can do it: https://github.com/konstantinstadler/country_converter

As shown in their documentation,

import country_converter as coco
some_names = ['United Rep. of Tanzania', 'DE', 'Cape Verde', '788', 'Burma', 'COG',
              'Iran (Islamic Republic of)', 'Korea, Republic of',
              "Dem. People's Rep. of Korea"]
standard_names = coco.convert(names=some_names, to='name_short')
print(standard_names)

Should give

 ['Tanzania', 'Germany', 'Cabo Verde', 'Tunisia', 'Myanmar', 'Congo Republic', 'Iran', 'South Korea', 'North Korea']

You can also specify the format you want the country names to be printed, by changing the to='name_short' to to='ISO2'

like image 124
Sohrab T Avatar answered Sep 15 '25 20:09

Sohrab T