Skip to main content

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_2019',
    'iso2', 'iso3', 'iso_num', 'calling_code', 'ccTLD',
    'latitude', 'longitude', 'flag', 'capital',
    'continent', 'sub_region', 'sovereign',
    'OECD', 'EU', 'EU_EEA', 'flag',
    'capital_latitude_sexa', 'capital_longitude_sexa',
    'capital_longitude', 'capital_latitude', 'gdp_2019',
    'gdp_per_capita_2019', 'gdp_per_capita_ppp_2019',
    'total_area', 'land_area', 'water_area'}, default 'iso3'}.

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.

Source Distribution

countre-0.0.2.tar.gz (37.9 kB view hashes)

Uploaded Source

Built Distribution

countre-0.0.2-py3-none-any.whl (37.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page