从国家和地区列表中过滤出地区名称

时间:2019-04-17 03:50:33

标签: python-3.x pandas dataframe

列表包含世界上所有国家以及地区,大洲等的名称。除了手动以外,还有没有其他更优雅的方法来过滤非国家名称?

一种解决方案是手动过滤名称,但这似乎...过于手工了?

没有

诸如拉丁美洲和加勒比海地区,西非和北美之类的名称必须在其自己的列表中。

1 个答案:

答案 0 :(得分:0)

您好,欢迎来到Stackoverflow。

假设您的列表名为my_list

使用pycountry软件包:

import pycountry

coutries = []

for country in list(pycountry.countries):
    countries.append(country)  # Creates a list full of official country names

# Print all the names which are not in countries but are un my_list
print([country for country not in countries and country in my_list])
相关问题