0
votes

I am trying to visualize some Covid-19 data (Covid Cases Ratio per Country) using folium module. For some reason a few countries appear to be black on the map, for example United States, and I'm using fill_color="YlGn". What is the problem right here?

import os
import folium
import pandas as pd

states = os.path.join('datas', 'countries.geo.json')

country_covid = os.path.join('datas', 'df.csv')
covid_data = pd.read_csv(country_covid, skiprows=0)

bins = list(covid_data['Cases'].quantile([0, 0.25, 0.5, 0.75, 1]))
m = folium.Map(location=[16, 34], zoom_start=5)

folium.Choropleth(
    geo_data=states,
    name="choropleth",
    data=covid_data,
    columns=['Country', 'Cases'],
    key_on='feature.properties.ADMIN',
    fill_color='YlGn',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Covid-19 Rate (%)',
    bins=bins,
    reset=True
).add_to(m)

folium.LayerControl().add_to(m)

m.save(outfile="map1.html")

Check out a screenshot of the map: Image

2

2 Answers

0
votes

When a country is "black", it actually means that there is no data for this country.

As I assume you have data for the United States, you should check that the code for the countries in the geojson and the ones in your pandas DataFrame are the same. The error is most likely there, the join between the country data and the geojson can't be made because of different keys.

If you post an exemple of your data and geojson, I could help you more.

0
votes

So the answer is that I had to actually edit the country's name in my geojson file in order to be the same with the equivalent name in the dataframe.