Folium renders the choropleth map with the police force boundaries but these are all grey and not colour matched for the data in the dataframe.
I have also ensured the new version of the documentation is followed i.e. folium.Choropleth. I have also checked to make sure I am key_on='feature.properties.pfa16nm' by checking the json in geojson.io Feature is spelt with a capital when checking the geojson however when I change it to this I get an error and no map renders. I have also renamed the file to only have the geojson as an extension and that didn't work.
import pandas as pd
import folium
import json
import os
adults_trafficked = pd.read_excel('Adults trafficked.xlsx')
force_boundaries = 'Police_Force_Areas_December_2016_Generalised_Clipped_Boundaries_in_England_and_Wales.geojson.json'
m = folium.Map([52.6333, -1.1333], zoom_start=4)
folium.Choropleth(
geo_data=force_boundaries,
data=adults_trafficked,
columns=['Police_Force', 'Adults_Exploited'],
key_on='feature.properties.pfa16nm',
threshold_scale=[0, 25, 50, 75, 100, 125, 150, 175],
fill_color='BuPu',
legend_name='Trafficked Humans',
).add_to(m)
m
I expect the Leaflet map to render with each police boundary shaded to the appropriate level based on the dataframe column data. The Chorpleth map renders perfectly with the boundaries however these are all grey and do not contain the tonal colour range one would expect. Please find the code, data and the json link here.
pfa16nm
in the json file. If you can make them match, your code should work. For example, excel file hasCumbria Constabulary
whereas the json file hasCumbria
. – Baris Tasdelen