pycountry icon indicating copy to clipboard operation
pycountry copied to clipboard

Add mapping between currencies and their countries

Open fertkir opened this issue 2 years ago • 1 comments

Here https://www.iso.org/iso-4217-currency-codes.html they say:

"The alphabetic code is based on another ISO standard, ISO 3166, which lists the codes for country names. The first two letters of the ISO 4217 three-letter code are the same as the code for the country name, and, where possible, the third letter corresponds to the first letter of the currency name."

Thus I need to do:

    currency_alpha3 = 'CNY'
    country_alpha2 = currency_alpha3[0:2]
    yuan = pycountry.currencies.get(alpha_3=currency_alpha3)
    china = pycountry.countries.get(alpha_2=country_alpha2)

Would be better if I could use the library API to derive country by currency instead of writing the code above.

fertkir avatar Nov 06 '22 06:11 fertkir

Also an opposite mapping could be done

fertkir avatar Nov 06 '22 13:11 fertkir

I m not sure it is possible using just current jsons: iso3166-1.json and iso4217.json. For example, I want to see the currency for the France, the country is:

    {
      "alpha_2": "FR",
      "alpha_3": "FRA",
      "flag": "🇫🇷",
      "name": "France",
      "numeric": "250",
      "official_name": "French Republic"
    },

and for EUR:

    {
      "alpha_3": "EUR",
      "name": "Euro",
      "numeric": "978"
    },

As you can see there is no common field. There should be another file with mapping country <> currency(s).

Irostovsky avatar Mar 16 '23 08:03 Irostovsky

https://github.com/srcagency/country-currencies/blob/master/data.csv

gsusI avatar Nov 09 '23 11:11 gsusI

@fertkir this data is available in the countryinfo library

>>> code = 'USA'
>>> import countryinfo
>>> usa_info = countryinfo.CountryInfo(code)
>>> usa_info.currencies()
['USD', 'USN', 'USS'] 

nschimmoller avatar Dec 08 '23 18:12 nschimmoller