得到错误,“列表索引必须是整数或切片,而不是浮点数”,使用folium在地图上绘制聚类点

问题描述 投票:1回答:1

我正在尝试使用在地图上创建聚类点。这是我使用的代码,但出现错误“列表索引必须是整数或切片,而不是浮点数”

# Create map
map_clusters = folium.Map(location=[kol_lat, kol_lng], zoom_start=11)

# Set color scheme for the clusters
x = np.arange(kclusters)
ys = [i + x + (i*x)**2 for i in range(kclusters)]
colors_array = cm.rainbow(np.linspace(0, 1, len(ys)))
rainbow = [colors.rgb2hex(i) for i in colors_array]

# Add markers to the map
markers_colors = []
for lat, lon, poi, cluster in zip(kolkata_merged['Latitude'], kolkata_merged['Longitude'], kolkata_merged['Neighbourhood'], kolkata_merged['Cluster Labels']):
    label = folium.Popup(str(poi) + ' (Cluster ' + str(cluster + 1) + ')', parse_html=True)
    map_clusters.add_child(
        folium.features.CircleMarker(
        [lat, lon],
        radius=5,
        popup=label,
        color=rainbow[cluster-1],
        fill=True,
        fill_color=rainbow[cluster-1],
        fill_opacity=0.7))

map_clusters

jupyter-notebook folium
1个回答
0
投票

请确保您的数据框中没有NaN值。然后尝试使用color=rainbow[int(cluster)-1],

© www.soinside.com 2019 - 2024. All rights reserved.