Jupyter notebook 获取错误“;列表索引必须是整数或切片,而不是float“;使用folium在地图上绘制簇点

Jupyter notebook 获取错误“;列表索引必须是整数或切片,而不是float“;使用folium在地图上绘制簇点,jupyter-notebook,folium,Jupyter Notebook,Folium,我正在尝试使用在地图上创建簇点。这是我使用过的代码,但我得到的错误是“列表索引必须是整数或片,而不是浮点” 确保数据帧中没有NaN值。 然后尝试使用color=rainbow[int(cluster)-1],确保数据帧中没有NaN值。 然后尝试使用color=rainbow[int(cluster)-1], # Create map map_clusters = folium.Map(location=[kol_lat, kol_lng], zoom_start=11) # Set color

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


确保数据帧中没有NaN值。
然后尝试使用
color=rainbow[int(cluster)-1],
确保数据帧中没有NaN值。 然后尝试使用
color=rainbow[int(cluster)-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