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
.
Este exercício faz parte do curso
Visualizing Geospatial Data in Python
Instruções do exercício
- 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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)