Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Extract Country Name (python)

I've a data frame column containing "text with country names" I need to extract country names like list of values and store it in a new column.

    import pycountry
    country_extract = []
    text = "Mexico|Mexico or Guatemala Tunesia Coastal Ecuador at xyz, 
    Jordan Amman (?) |United States|United States|Canada |Egypt, from xyz 
    of abcd, Cairo "
    for country in pycountry.countries:
        if country.name in text:
            df_metobjects['country_extract'] = (country.name)
            print(country.name)

Output - Canada Ecuador Egypt Guatemala Jordan Mexico United States

I need to process on a column and store the extracted data as a list in a new column

Comments