Package to get country data from country names.
Project description
Country Regex Package
countre is a package with functions to get standardised names or codes from country names, as well as additional country information. Country names often differ between data sources, therefore having standardised codes for each country makes it easy to merge data from multiple sources.
The countries included are those defined by the International Organization for Standardization. The list can be found here. The sources of the country data can be found here.
Installation
countre can be installed via pip from PyPi:
pip install countre
Functions can then be accessed in the following ways:
import countre
countre.country_info()
or
from countre import country_info
country_info()
Functions
countre.country_info(country_list, variables='iso3', no_match='no_match')
Parameters:
country_list : list, Pandas series or Numpy array
Country names, ISO 3166-1 alpha-2 codes or ISO 3166-1 alpha-3 codes.
variables : str, list, default 'iso3'
Select one or more from:
{'country', 'country_short', 'population_2020',
'iso2', 'iso3', 'iso_num', 'calling_code', 'ccTLD',
'latitude', 'longitude', 'flag', 'capital',
'continent', 'sub_region', 'sovereign',
'OECD', 'EU', 'EU_EEA', 'flag', 'country_sv',
'capital_latitude_sexa', 'capital_longitude_sexa',
'capital_longitude', 'capital_latitude', 'gdp_2020',
'gdp_per_capita_2020', 'gdp_per_capita_ppp_2020',
'total_area', 'land_area', 'water_area'}.
no_match : str, default 'no match'
String returned for each country if no match is found.
Returns:
List of values if only one variable is given.
Dictionary if more than one variable is given. The dictionary keys are
the variable names and the values are lists of values. This means it can
be used as follows to create a data frame with Pandas:
pd.DataFrame(country_info(['GBR', 'SWE'], ['country', 'capital']))
countre.eu_27(code='country')
Parameters:
code : str, default 'country'
One from: {'country', 'iso2', 'iso3'}
Returns:
List of either country names, ISO 3166-1 alpha-2 codes or ISO 3166-1 alpha-3
codes of the 27 EU member countries.
countre.oecd(code='country')
Parameters:
code : str, default 'country'
One from: {'country', 'iso2', 'iso3'}
Returns:
List of either country names, ISO 3166-1 alpha-2 codes or ISO 3166-1 alpha-3
codes of the 37 OECD member countries.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.