首页 > 解决方案 > 在 jupyter 中带有 Folium 的 Python 映射错误

问题描述

我正在尝试将地图导入 jupyter,但它不希望任何工作。我在 .csv 中有两列,称为

df[['latitude', 'longitude']]
df.head(20)

到目前为止一切都很好

当我尝试表示它时(我已经做了很多尝试)或者它给了我空白,或者在等待大约 10 分钟后我必须重新启动 jupyter,因为它阻塞了。我声明我有大约 65000 行经纬度,我使用的代码是这样的:

m = folium.Map([41.4, 12.7], zoom_start=8)
m

我正确地看到了地图

for index, row in df.iterrows():
folium.Marker([row['latitude'], row['longitude']], 
              #popup=row['Location'],
              icon=folium.Icon(icon='cloud')
             ).add_to(m)
m

我得到了我上面描述的问题....感谢那些可以帮助我的人

标签: pythonjupyterfolium

解决方案


尝试使用FastMarkerCluster.

import folium
from folium import plugins

locations = []
for index, row in df.iterrows():
    locations.append([row['latitude'], row['longitude'])

marker_cluster = plugins.FastMarkerCluster(locations).add_to(m)

m

现在您的点首先被聚集在一起,如果您放大单个位置将是可见的。


推荐阅读