How to use countrynames - 10 common examples

To help you get started, we’ve selected a few countrynames examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alephdata / opensanctions / opensanctions / models.py View on Github external
def country(self, name):
        self.country_name = name
        self.country_code = countrynames.to_code(name)
github alephdata / opensanctions / opensanctions / util.py View on Github external
def normalize_country(name):
    return countrynames.to_code(name)
github alephdata / opensanctions / peplib / source.py View on Github external
def normalize_country(self, name):
        return countrynames.to_code(name)
github alephdata / aleph / aleph / data / parse.py View on Github external
def parse_country(country, guess=True):
    """Determine a two-letter country code based on an input.

    The input may be a country code, a country name, etc.
    """
    if guess:
        country = countrynames.to_code(country)
    if country is not None:
        country = country.lower()
        if is_country_code(country):
            return country
github alephdata / followthemoney / followthemoney / types / country.py View on Github external
def clean_text(self, country, fuzzy=False, **kwargs):
        """Determine a two-letter country code based on an input.

        The input may be a country code, a country name, etc.
        """
        code = country.lower().strip()
        if code in self.codes:
            return code
        country = countrynames.to_code(country, fuzzy=fuzzy)
        if country is not None:
            return country.lower()
github openclimatedata / global-carbon-budget / scripts / emissions-transfers.py View on Github external
from countrynames import to_code_3

emissions_transfers_csv = root / "data/emissions-transfers.csv"

# Emissions transfers
emissions_transfers = pd.read_excel(
    excel_national,
    sheet_name="Emissions Transfers",
    skiprows=8,
    index_col=0
)
emissions_transfers.index.name = "Year"
emissions_transfers = emissions_transfers.T
emissions_transfers.index.rename("Name", inplace=True)

emissions_transfers["Code"] = [to_code_3(i) or i
                               for i in emissions_transfers.index]

emissions_transfers = emissions_transfers.reset_index().drop(
    "Name", axis=1)


emissions_transfers = pd.melt(
    emissions_transfers,
    id_vars="Code",
    var_name="Year",
    value_name="Emissions-Transfers"
)

emissions_transfers.sort_values(["Code", "Year"], inplace=True)
emissions_transfers.dropna(inplace=True)
github openclimatedata / global-carbon-budget / scripts / territorial-emissions.py View on Github external
# Territorial GCB emissions

territorial_gcb = pd.read_excel(
    excel_national,
    sheet_name="Territorial Emissions",
    skiprows=16,
    index_col=0,
    usecols="A:HW"
)
territorial_gcb.index.name = "Year"

territorial_gcb = territorial_gcb.T
territorial_gcb.index.rename("Name", inplace=True)

territorial_gcb["Code"] = [to_code_3(i) or i for i in territorial_gcb.index]

territorial_gcb = territorial_gcb.reset_index().drop("Name", axis=1)

territorial_gcb = pd.melt(
    territorial_gcb,
    id_vars='Code',
    var_name="Year",
    value_name="Emissions"
)

territorial_gcb.sort_values(["Code", "Year"], inplace=True)

territorial_gcb['Source'] = np.where(
    territorial_gcb.Year < 2017, "CDIAC", "BP")
github openclimatedata / global-carbon-budget / scripts / territorial-emissions-cdiac.py View on Github external
territorial_cdiac_csv = root / "data/territorial-emissions-cdiac.csv"

# Territorial CDIAC emissions

territorial_cdiac = pd.read_excel(
    excel_national,
    sheet_name="Territorial Emissions CDIAC",
    skiprows=13,
    index_col=0
)
territorial_cdiac.index.name = "Year"

territorial_cdiac = territorial_cdiac.T
territorial_cdiac.index.rename("Name", inplace=True)

territorial_cdiac["Code"] = [to_code_3(i) or i
                             for i in territorial_cdiac.index]

territorial_cdiac = territorial_cdiac.reset_index().drop("Name", axis=1)

territorial_cdiac = pd.melt(
    territorial_cdiac,
    id_vars="Code",
    var_name="Year",
    value_name="Emissions"
)

territorial_cdiac.dropna(inplace=True)

territorial_cdiac.sort_values(["Code", "Year"], inplace=True)

territorial_cdiac.to_csv(
github openclimatedata / global-carbon-budget / scripts / consumption-emissions.py View on Github external
from countrynames import to_code_3

consumption_emissions_csv = root / "data/consumption-emissions.csv"

# Consumption emissions
consumption_emissions = pd.read_excel(
    excel_national,
    sheet_name="Consumption Emissions",
    skiprows=8,
    index_col=0
)
consumption_emissions.index.name = "Year"
consumption_emissions = consumption_emissions.T
consumption_emissions.index.rename("Name", inplace=True)

consumption_emissions["Code"] = [to_code_3(i) or i
                                 for i in consumption_emissions.index]

consumption_emissions = consumption_emissions.reset_index().drop(
    "Name", axis=1)

consumption_emissions = pd.melt(
    consumption_emissions,
    id_vars="Code",
    var_name="Year",
    value_name="Consumption-Emissions"
)

consumption_emissions.sort_values(["Code", "Year"], inplace=True)

consumption_emissions.dropna(inplace=True)
github alephdata / countrynames / countrynames / __init__.py View on Github external
def to_code_3(country_name, fuzzy=False):
    """Given a human name for a country, return a three letter code.

    Arguments:
        ``fuzzy``: Try fuzzy matching based on Levenshtein distance.
    """
    code = to_code(country_name, fuzzy=fuzzy)
    if code and len(code) > 2:
        return code
    elif code is None:
        return code
    else:
        return mappings[code]

countrynames

A library to map country names to ISO codes.

MIT
Latest version published 3 days ago

Package Health Score

72 / 100
Full package analysis

Similar packages