python-3.x - 将不同的国家替代名称合并到官方名称下

标签 python-3.x

我正在搜索一个列表或 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/

相关文章:

python - Strawpoll.me API 对于我的 Python 程序返回 "400 Bad Request",但可以在终端上运行

python-3.x - 如何在 IDLE 断点处停止

python - exit() 不适用于 cx_freeze

python - 不同连续子数组的数量

python - 通过从第一个列表中获取第一项和从第二个列表中获取最后一项来创建新列表

mysql - 如何从 auth_user 表中按 django 中的 date_joined 顺序获取我之后的所有用户记录 [已关闭]

python-3.x - Anaconda 和升级到新的 M1 Mac

python - 如何在 Python 中停止后台线程

python-3.x - 如何使用python从具有相同属性的多个视频文件中删除两个音频流中的一个特定流?

javascript - 尝试使用 CustomJS 加载新图像时 Bokeh 查找临时文件