Using country data derived from wikipedia, this package provides conversion functions between ISO country names, country-codes, and continent names.
Questions tagged [pycountry-convert]
16 questions
4
votes
2 answers
How do I convert an IOC country code to country name?
I have a pandas dataframe
import pandas as pd
s = pd.DataFrame({'ioc' : ['ESP', 'CYP', 'USA', 'ESP', 'NED']})
and I want to return
out = pd.DataFrame(
{'ioc' : ['ESP', 'CYP', 'USA', 'ESP', 'NED'],
'countryName' : ['Spain', 'Cyprus',…

Amin Selim
- 71
- 4
2
votes
0 answers
Pycountry: how to get country name, language name and alpha_3 and find matches from a language list
I have a list of languages and dialects.
For these languages I need to get Alpha_3 and country.name (if availavle).
import pycountry
my_langs = ['Aachen German', 'Aalsters', 'Abkhaz', 'Afrikaans', 'Albanian', 'Gheg', 'Altay', 'Old…

Witness1123
- 93
- 6
2
votes
2 answers
How can I increase DataFrame's apply function efficiency?
I know it is kinds of impossible but I still look forward to an alternative. Here is my DataFrame (read from csv file):
I need to recognize the country and continent where the location is, and here is my idea:
import pandas as pd
! pip install…

Memphis Meng
- 1,267
- 2
- 13
- 34
1
vote
2 answers
Try / except not working with a specific exception in Python
I'm trying to solve a specific error from a library (pycountry_convert) in a code with try / except, but when I use the except to avoid this case it just doesn't work. I've tried so many things to solve this.
Here is the code
import…

Yuri Reis Valete
- 11
- 2
1
vote
0 answers
I cannot get pycountry_convert to work in my code
I came across this example to convert country to continent
I could not find the package pycountry_convert so I installed pycontry and pycountry-convert but using both I cannot run the following code successfully.
I get this issue AttributeError:…

abc
- 39
- 6
1
vote
0 answers
Change name of any state, county, regions, or their abbreviations to country name in python NLTK or other packages
I have a list of locations that is mixed with states, cities and countries, counties and regions, in abbreviations and some in full. For instance, NY, CA, England, UK, USA, Minnesota, London, Bradford, etc. I want it all to be converted to countries…

Julius Sechang Mboli
- 60
- 8
0
votes
0 answers
convert CN_CODE in pandas using pycountry
Hi given that that column hightlighted is CN_code of the country (included inside original dataset). How do I want to group each of the country into the continent if I got like 66 country. I read few about using pycountry_convert but there are no…

Gexplode97
- 11
- 2
0
votes
0 answers
Unable to use pycountry search_fuzzy to look up the alpha_3 based on given countries names, any better ideas?
I have the following 122 countries which I couldn't look up their corresponding alpha 3 code. I tried search_fuzzy but nothing is found.
By looking at some of the countries names, I can "manually" assign the alpha 3 based on common knowledge (such…

user032020
- 406
- 2
- 13
0
votes
2 answers
converting countries to continents when there is more than one country per row
I have a column with country where each row has more than one country listed. I want to convert each country to continent. In the past I have used country converter, but when I try to use it in this case, I get an error because there is more than…

Rebecca James
- 383
- 2
- 12
0
votes
1 answer
How to convert a list of countries into their corresponding continents using pycountry_convert?
I am trying to convert the list of countries in my dataset into their corresponding continents . I am using this code for help link:
country convert to continent
but i got error when try to execute the code given above :
" KeyError: "Invalid Country…

Fahad Najeeb
- 1
- 1
0
votes
1 answer
pycountry | extract values or convert Country object to iterable
How can I extract values in Country object or convert to an iterable?
Maybe specicially this isn't possible.
Goal: lookup a country code using alpha_2 param and extract all values.
Usage
pip install pycountry
import…

DanielBell99
- 896
- 5
- 25
- 57
0
votes
1 answer
Can one add the output of a function in Python as a column to a dataframe
I have an array of countries. I would like to run this array through a function and append the output of the function as a column to a dataframe.
I used the apply method but keep getting a KeyError. I am not sure what I am doing wrong.
Code
import…

gulniza
- 3
- 1
0
votes
1 answer
Get full language name from iso-639 code using pycountry
I have the following problem I am trying to solve. I have a list of iso-639 languages that I retreived using langdetect with the following code
def try_detect(cell):
try:
detected_lang = detect(cell)
except:
detected_lang =…

Serge de Gosson de Varennes
- 7,162
- 3
- 18
- 39
0
votes
0 answers
How to make a slider to slide across columns to visualize data using plotly and pycountry
I am trying to create a visual to show country wise GDP across years. My dataframe contains data from 1980 to 2013. A small (made-up) sample of it is here:
Country|1980 YR1980|1981 YR1981|1982 YR 1982|...
A | 1 | - | 2 …

K C
- 413
- 4
- 15
0
votes
1 answer
How do I convert the name of a country to a continent with separate lists of current and outdate countries
How could I convert country name to continent name in a list of countries, some currently in existence and others no longer existing (ex. USSR)?
I have a table of data from countries around the world spanning the last fifty years. I want to add a…

jpank
- 13
- 3