Creating markers and popups in folium

Visualizing Geospatial Data in Python

Mary Van Valkenburg

Data Science Program Manager, Nashville Software School

for row in schools_in_dist1.iterrows():
    row_values = row[1]
    print(row_values)
name                              Alex Green Elementary
lat                                              36.253
lng                                            -86.8322
geometry                 POINT (-86.8322292 36.2529607)
district                                              1
center      POINT (-86.86086595994405 36.2628221811899)
Name: 1, dtype: object
name                               Bellshire Elementary
lat                                             36.2697
lng                                            -86.7623
geometry               POINT (-86.76230026 36.26968766)
district                                              1
center      POINT (-86.86086595994405 36.2628221811899)
Name: 8, dtype: object
Visualizing Geospatial Data in Python

Building marker locations

# Construct a folium map for school district 1
district1_map = folium.Map(location = district_center, zoom_start = 11)

#create a marker for each school
for row in schools_in_dist1.iterrows():
    row_values = row[1]
    location = [row_values['lat'], row_values['lng']]
    marker = folium.Marker(location = location)
    marker.add_to(district1_map)

display(district1_map)
Visualizing Geospatial Data in Python

Building marker locations

street map of Nashville with folium markers

Visualizing Geospatial Data in Python

Creating popups from data in a DataFrame

# Construct a folium map for school district 1
district1_map = folium.Map(location = district_center, zoom_start = 11)

# Create a marker for each school
for row in schools_in_dist1.iterrows():
    row_values = row[1]
    location = [row_values['lat'], row_values['lng']]
    popup = popup = '<strong>' + row_values['name'] + '</strong>'
    marker = folium.Marker(location = location, popup = popup)
    marker.add_to(district1_map)

display(district1_map)
Visualizing Geospatial Data in Python

Creating popups from data in a DataFrame

street map of nashville with markers and a popup that says 'Whites Creek High School'

Visualizing Geospatial Data in Python

Troubleshooting popups

street map of nashville with markers and a popup that says 'NaN'

Visualizing Geospatial Data in Python

Let's practice!

Visualizing Geospatial Data in Python

Preparing Video For Download...