Я импортирую столбец из 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
Подробнее здесь: https://stackoverflow.com/questions/789 ... -countries