I have a geopandas dataframe (dfg) with the following structure
lsoa11cd object
A8 float64
OBJECTID int64
LSOA11CD object
LSOA11NM object
LSOA11NMW object
Shape__Area float64
Shape__Length float64
geometry geometry
I have tried to generate a choropleth via folium, but all the regions are showing as a flat grey.
m = folium.Map(
location=[52.2405, -0.9027],
zoom_start=13
)
folium.Choropleth(
geo_data=dfg,
name ='choropleth',
data=dfg,
columns=['LSOA11CD', 'A8'],
Fill_colour='RdPu',
fill_opacity=0.5,
line_opacity=0.2
).add_to(m)
folium.LayerControl().add_to(m)
m
All the regions draw correctly, but all the same colour.
It works nicely using the plot function
dfg.plot(column='A8')
I feel like I am missing something obvious
I think you are missing the key_on
parameter in the folium.Choropleth
, which is basically the link between your GeoJson and your pandas DataFrame.
It uses your GeoJson keys to know where to do the join. It can be something like 'feature.id'
, but you will have to provide an example of your GeoJson so that I can tell you the exact key.