Skip to content Skip to sidebar Skip to footer

Choropleth Map Is Not Showing Color Variation In The Output

I am not getting any color variation in my output map even after the choropleth is linked with the geo_data and the data frame is linked with data parameter in the choropleth metho

Solution 1:

After reading the data what I found was you did not convert the data type of Community Area column to string type as the geojson file contains the key in the form of string. So the data type of both the key and column should match.

Here is a full fledged solution to your answer

# importing librariesimport pandas as pd
from pandas import read_csv
import folium
import os
import webbrowser
# read the data
crimes = read_csv('Dataframe.csv',error_bad_lines=False)
# convert float to int then to string
crimes['Community Area'] = crimes['Community Area'].astype('int').astype('str')
# choropleth map
vis = 'Community_Areas.geojson'
m = folium.Map(location = [41.878113, -87.629799], zoom_start = 10, tiles = "cartodbpositron")
m.choropleth(geo_data=vis, data = crimes, columns = ['Community Area', 'count'], fill_color = 'YlGn', key_on = 'feature.properties.area_num_1')
folium.LayerControl().add_to(m)
m.save('map.html')
webbrowser.open('map.html')

Please comment if you find difficulty in understanding any part of code. For the key_on parameter you can also try feature.properties.area_numbe

Post a Comment for "Choropleth Map Is Not Showing Color Variation In The Output"