Convert country names in many languages to another name or code.

def countryname(
  sourcevar: Any,
  destination: str = "country.name.en",
  *,
  nomatch: Any = _DEFAULT_NOMATCH,
  warn: bool = True
)

Description

The function makes two passes over the data. First it detects country-name variations in many languages extracted from the Unicode Common Locale Data Repository. It then applies the English country-name patterns used by countrycode to unresolved values.

Because the two-pass approach is permissive, some names can be ambiguous, such as Saint Martin versus Saint Martin (French part). Use countrycode(x, "country.name", "country.name") when stricter English name matching is preferable.

Arguments

sourcevarCountry names to convert. Non-ASCII names are supported. Accepts the same scalar and container types as countrycode.
destinationDestination country-name or coding field. Defaults to the standardized English name, "country.name.en".
nomatchReplacement for unmatched values. By default they become None. Pass None to preserve the original input, or pass a scalar or same-length sequence of replacements.
warnEmit warnings listing values that could not be matched.

Value

Converted names or codes, preserving the scalar or container type of sourcevar where supported.

Examples

countryname(["Barbadas", "Sverige", "UK"])
countryname(["Barbadas", "Sverige"], destination="iso3c")