AskReference
ApplicationIntermediate

What Python package is used in Example 17-10 to convert two-letter ISO country codes to three-letter ISO codes for Plotly choropleth maps?

The package is country_converter, imported as coco in Example 17-10.

In Example 17-10, the code runs `pip install country_converter` and then imports it with `import country_converter as coco`. It calls `coco.convert(names=iso2_codes, to="ISO3")` to map the two-letter ISO country codes from the creature data to three-letter codes used by Plotly's choropleth function.

Key points

  • country_converter is the package used.
  • It is imported as `coco`.
  • The conversion call is `coco.convert(names=iso2_codes, to="ISO3")`.
  • The converted codes are passed to `px.choropleth` via `locations=iso3_codes`.
Source:FastAPI: Modern Python Web Development· Data Discovery and Visualization· p. 242–250

Related questions

Cover of FastAPI: Modern Python Web Development

FastAPI: Modern Python Web Development

Bill Lubanovic;

First Edition · O'Reilly Media, Inc.

View this ebook