import folium
# In order to create a Choropleth map, we need a GeoJSON file that defines
# the areas/boundaries of the state, county, or country that we are interested in
world_geo = r'world_countries.json'
threshold_scale = np.linspace(df['Total crimes'].min(),
df['Total crimes'].max(),
6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration
# create a plain world map
world_map = folium.Map(location=[0, 0], zoom_start=2)
# Create choropleth
world_map.choropleth(
geo_data=world_geo,
data=df,
columns=['Country', 'Total crimes'],
key_on='feature.properties.name',
fill_color='YlOrRd',
threshold_scale=threshold_scale,
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Crime prone areas',
reset=True
)
# display map
world_map