使用python包pycountry匹配数据中的国家/地区

时间:2017-09-03 13:44:09

标签: python pandas

我正在尝试将我的数据中的国家与蟒蛇内置的pycountry包匹配。运行后我收到此错误

raise AttributeError

AttributeError的

countries_lookup = {}
countries = list(pycountry.countries)
for country in countries:    
    countries_lookup[country.alpha2]=country.name
country_names = list(countries_lookup.values())
country_names = [country.lower() for country in country_names]
country_names = set(country_names)

应该是什么问题?

1 个答案:

答案 0 :(得分:1)

只是一个错误的纠正:

countries_lookup[country.alpha_2]=country.name
#-----------------------------^