I am trying to display a folium choropleth heatmap using a custom topoJSON file and a dataframe. The map generates with a uniformly shaded choropleth instead of the expected heatmap.
Heres a snippet of code I am using (excludes basic imports, creation of dataframe):
cols = ['dma', 'values']
center_us_long_lat = [39.50, -98.35]
topo_path = r'../../data/designated_marketing_areas_us_topo.json'
us_map = folium.Map(location=center_us_long_lat,attr='dma_code',
tiles='Mapbox Bright', zoom_start=4, min_zoom=4)
us_map.choropleth(geo_path=topo_path, topojson='objects.nielsen_dma',
data=df, columns=cols,
fill_opacity=0.7,
key_on="feature.properties.dma",
line_color='white', fill_color='YlOrRd',
highlight=True
)
The output looks like this:
I've tried adjusting the key_on
argument to feature.dma
but this results in the same output.
As a reference here's a sample of the df
data:
In[1]:
df.head():
Out[1]:
dma values
1 501 16.749
2 740 8.858
3 807 15.790
4 511 15.315
5 798 8.425
The topojson can be found here
What am I doing wrong? Thanks!
I know this might sound silly, but I always find these issues come down to mismatched data types or leading/lagging spaces. Good luck!