So I have previously done a choropleth map and it was working. This time I used the same approach but its not showing anymore
map and unis_colleges have the same shape, as well as index The map and the csv file:text
#put a choropleth on top of the map
m = folium.Map(location=[48.0196, 66.9237], tiles='cartodbpositron', zoom_start=6)
# Add a choropleth map to the base map
folium.Choropleth(geo_data=map.__geo_interface__, name = 'choropleth',
data=student_total, columns = ['unis_colleges'],
key_on="feature.id",
fill_color='YlGnBu',
legend_name='Number of students per region 2023').add_to(m)
# Display the map
m
That's most likely a CRS issue. I can reproduce the behaviour you describe with this .shp
file (that is projected in EPSG:3857) along with the .csv
file you provided. So, assuming what you call map
(better to name it gdf
) is a GeoDataFrame
, you can do :
m = folium.Map(location=[48.0196, 66.9237], tiles="cartodbpositron", zoom_start=6)
folium.Choropleth(
geo_data=gdf.to_crs("EPSG:4326").__geo_interface__, # here we use `.to_crs`
name="choropleth",
data=student_total,
columns=["regions", "unis_colleges"], # folium requires 2 columns
key_on="feature.properties.ADM1_EN", # replace ADM1_EN if needed
fill_color="YlGnBu",
legend_name="Number of students per region 2023",
).add_to(m)
Output (m
) :