Folium choropleth with markers and popups
Now you will add a marker to the center of each council district that shows the district number along with the count of building permits issued in 2017 for that district. The map you created in the last exercise is available as m
.
This exercise is part of the course
Visualizing Geospatial Data in Python
Exercise instructions
- Find the centroid for each council district and store it in a new column,
center
in thedistricts_and_permits
GeoDataFrame. - Iterate through
districts_and_permits
and add a marker at each district'scenter
. Remember to reverse the coordinate pair. - Create popups within your for loop to display the district number and the count of permits issued.
- Add the markers to your map with
.add_to()
and display it.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create center column for the centroid of each district
districts_and_permits['center'] = districts_and_permits.____.____
# Build markers and popups
for row in districts_and_permits.iterrows():
row_values = row[1]
center_point = row_values[____]
location = [center_point.____, center_point.____]
popup = ('Council District: ' + str(row_values[____]) +
'; ' + 'permits issued: ' + str(row_values[____]))
marker = folium.Marker(location = location, popup = popup)
marker.____(m)
# Display the map
display(m)