我正在搜索一个列表或 python 包,以帮助我在一个名称下统一不同的国家/地区名称。
例如:
USA, SUA, United States, Unites States of America
Germany, Federal Republic of Germany, Deutschland, Duitsland
我想把它们合并到正式名称下,并分配给它们 is 标准。
最佳答案
这个包,country_converter,可以做到:https://github.com/konstantinstadler/country_converter
如他们的文档所示,
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)
应该给
['Tanzania', 'Germany', 'Cabo Verde', 'Tunisia', 'Myanmar', 'Congo Republic', 'Iran', 'South Korea', 'North Korea']
您还可以通过将 to='name_short'
更改为 to='ISO2'
关于python-3.x - 将不同的国家替代名称合并到官方名称下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60100484/