Tạo marker và popup trong folium

Trực quan hóa dữ liệu không gian địa lý bằng 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
Trực quan hóa dữ liệu không gian địa lý bằng Python

Tạo vị trí marker

# 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)
Trực quan hóa dữ liệu không gian địa lý bằng Python

Tạo vị trí marker

bản đồ đường phố Nashville với các marker folium

Trực quan hóa dữ liệu không gian địa lý bằng Python

Tạo popup từ dữ liệu trong 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)
Trực quan hóa dữ liệu không gian địa lý bằng Python

Tạo popup từ dữ liệu trong DataFrame

bản đồ đường phố Nashville với marker và popup ghi 'Whites Creek High School'

Trực quan hóa dữ liệu không gian địa lý bằng Python

Khắc phục sự cố popup

bản đồ đường phố Nashville với marker và một popup ghi 'NaN'

Trực quan hóa dữ liệu không gian địa lý bằng Python

Cùng luyện tập nào!

Trực quan hóa dữ liệu không gian địa lý bằng Python

Preparing Video For Download...