Skip to content
Advertisement

Color map based on dataframe with countries’ counts values

I have a dataframe called country which contains country_code and frequency counts for countries.

country_code frequency
0 US 17600
1 CN 8572
2 KR 1121
3 JP 299
4 DE 199

I wrote a code to plot distribution of countries on a world map:

JavaScript

The result I got:

Output data

Something is wrong with the code, I cannot find the reason why the distribution is not shown on the map at all. Could you please help me to correct it? Thanks!

Advertisement

Answer

The choroplethmap in plotly needs to specify in which format the country name data is represented.

locationmode: str One of ‘ISO-3’, ‘USA-states’, or ‘country names’ Determines the set of locations used to match entries in locations to regions on the map.

The country name column is a two-letter abbreviation, so it needs to be converted to a three-letter abbreviation. I had to correct it manually because I had a small number of data.

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement