1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Comparing dictionary of countries with a column of countries

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I have a dictionary/country list which i took from pycountry (list(pycountry.countries)

    I am importing a column from excel called CountryNames

    i thought by creating 2 for loops, i could then compare to see if my CountryNames is found in the PyCountry list

    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


    I want to check to see if a countryName (from the excel column) is in the pycountry list

    Continue reading...

Compartilhe esta Página