Невозможно использовать pycountry search_fuzzy для поиска alpha_3 на основе заданных названий стран, есть идеи получше?
У меня есть следующие 122 страны, для которых я не смог найти соответствующий код альфа 3. Я пробовал search_fuzzy, но ничего не нашел.
Глядя на названия некоторых стран, я могу «вручную» назначить альфу 3 на основе общеизвестных фактов (например, создать диск для переименования). Однако мне интересно, есть ли лучший способ поиска альфы 3 автоматизированным способом, например, с помощью другой функции из pycoutry или даже re?
Любые предложения и советы приветствуются.
import pandas as pd
import numpy as np
import regex as re
import pycountry
missing = ['Americas', 'Asia', 'Australia and New Zealand', 'Bolivia (Plurinational State of)', 'Caribbean', 'Central America', 'Central and Southern Asia', 'Central Asia', 'China, Hong Kong Special Administrative Region', 'China, Macao Special Administrative Region', 'Democratic Republic of the Congo', 'Eastern Africa', 'Eastern and South-Eastern Asia', 'Eastern Asia', 'Eastern Europe', 'Europe', 'Europe and Northern America', 'Iran (Islamic Republic of)', 'Landlocked developing countries (LLDCs)', 'Latin America and the Caribbean', 'Least Developed Countries (LDCs)', 'Melanesia', 'Micronesia (Federated States of)', 'Middle Africa', 'Northern Africa', 'Northern Africa and Western Asia', 'Northern America', 'Northern Europe', 'Oceania', 'Oceania (exc. Australia and New Zealand)', 'Small island developing States (SIDS)', 'South America', 'South-Eastern Asia', 'Southern Africa', 'Southern Asia', 'Southern Europe', 'Sub-Saharan Africa', 'Türkiye', 'Venezuela (Bolivarian Republic of)', 'Western Africa', 'Western Asia', 'Western Europe', 'World', 'European Union (27)', 'Chinese Taipei', 'UAE', 'Belgium-Luxembourg', 'Channel Islands', 'China, Hong Kong SAR', 'China, Macao SAR', 'China, mainland', 'China, Taiwan Province of', 'Czechoslovakia', 'Ethiopia PDR', 'French Guyana', 'Netherlands Antilles (former)', 'Pacific Islands Trust Territory', 'Serbia and Montenegro', 'Sudan (former)', 'Svalbard and Jan Mayen Islands', 'United States Virgin Islands', 'USSR', 'Wallis and Futuna Islands', 'Yugoslav SFR', 'Global average', 'Cocos Islands', 'Macquarie Island', 'Northern Mariana Islands and Guam', 'Comoro Islands', 'Glorioso Islands', 'Juan de Nova Island', 'Bassas da India', 'Ile Europa', 'Ile Tromelin', 'Azores', 'Cape Verde', 'Canary Islands', 'Prince Edward Islands', 'Crozet Islands', 'Amsterdam Island and Saint Paul Island', 'Kerguelen Islands', 'Heard and McDonald Islands', 'Republique du Congo', 'Clipperton Island', 'Puerto Rico and Virgin Islands of the United States', 'Guadeloupe and Martinique', 'Faeroe Islands', 'Line Islands (Kiribati)', 'Phoenix Islands (Kiribati)', 'Howland Island and Baker Island', 'Guinea Bissau', 'Ivory Coast', 'Gilbert Islands (Kiribati)', 'Northern Saint-Martin', 'East Timor', 'Oecussi Ambeno', 'Laos', 'Republic of Congo', 'Dem. Rep. Congo', 'ASEAN', 'BRIICS', 'DRC', 'EA19', 'EECCA', 'EU27_2020', 'European Union', 'G20', 'G7M', 'Lao PDR', 'OECD', 'OECDAM', 'OECDAO', 'OECDE', 'Grenade', 'Korea, Rep.', 'Egypt, Arab Rep.', 'Iran, Islamic Rep.', 'Korea (Rep.)', 'Hong Kong, China', 'Iran (Islamic Republic)', 'Cote dIvoire', 'Congo (Democratic Republic)']
not_found = []
for country in missing:
try:
print(pycountry.countries.search_fuzzy(country))
print(country)
except:
print('not found')
not_found.append(country)
print(len(missing)) #122
print(len(not_found)) #122