Сравнение словаря стран со столбцом странPython

Программы на Python
Anonymous
Сравнение словаря стран со столбцом стран

Сообщение Anonymous »

У меня есть словарь/список стран, который я взял из pycountry (list(pycountry.countries)
Я импортирую столбец из Excel под названием CountryNames
Я подумал, что создав 2 цикла for, я мог бы затем сравнить, есть ли мои CountryNames в списке PyCountry

Код: Выделить всё

 import pandas as pd
from langdetect import detect
from googletrans import Translator
import pycountry

df =  pd.read_excel(r"V1.xlsx")
input_countries = df['CountryName']

# Ensure the column 'CountryName' exists in the CSV
if 'Sold To Customer Country' not in df.columns:
raise ValueError("CountryName' column")

t = list(pycountry.countries)

# loop through column of countries
for name in input_countries:
# loop through country name (pycountry)
for pycountry.name in t:
# comparison - Show country names
if input_countries in t:
input_countries
else:
'invalid'enter code here
Я хочу проверить, есть ли имя страны (из столбца Excel) в списке pycountry

Подробнее здесь: https://stackoverflow.com/questions/789 ... -countries

Вернуться в «Python»