我在构建python叶片地图时遇到一些错误

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

首先,请不要对我进行评判,但我正在尝试用我的国家麦当劳所有地方的标记物来绘制一张大草坪地图。我所做的第一件事是使用webscraper下载该地点的所有nqmes和地址其次,我试图将它们与geopy库转换为经纬度点,以便将其加载到大叶标记中

import folium
import pandas as pd
from geopy.geocoders import ArcGIS

snifim_df = pd.read_csv('Snif.csv')
nom = ArcGIS()
snifim_df['LAT'] = snifim_df['Address'].apply(nom.geocode).apply(lambda x:x.latitude) 
snifim_df['LON'] = snifim_df['Address'].apply(nom.geocode).apply(lambda x:x.longitude) 

我的叶代码看起来像这样

Mcmap = folium.Map(location=[35.58, -92.09], zoom_start = 6)
fg = folium.FeatureGroup(name = "McDonalds")

snif_lat = list(snifim_df['LAT'])
snif_lon = list(snifim_df['LON'])
snif_name = list(snifim_df['Name'])

for lat,lon, name in zip(snif_lat,snif_lon,snif_name):
    fg.add_child(folium.Marker(location=[lat,lon],popup=name))

Mcmap.add_child(fg)
Mcmap.save("test.html")

每当我运行此代码时,就会发生两个错误之一:1)我收到一个geopy超时错误“ geopy.exc.GeocoderTimedOut:服务超时”2)代码运行没有错误,但html映射未出现在我的文件夹中

我的数据集看起来像这样,有169行:enter image description here

有人可以救救我,并向我解释发生了什么问题以及如何解决?在此先感谢:)

python python-3.x folium geopy
1个回答
0
投票

如果使用叶0.10.0,只需测试代码:

    snifim_df = pd.DataFrame({'name':['york', 'land', 'wu'], 'lat':[35.09,36.12,35.13],
                      'lon':[-90.18, -91.25, -90.88]}) 
    Mcmap = folium.Map(location=[35.58, -92.09], zoom_start = 6)
    fg = folium.FeatureGroup(name = "McDonalds")

    snif_lat = list(snifim_df['lat'])
    snif_lon = list(snifim_df['lon'])
    snif_name = list(snifim_df['name'])

    for lat,lon, name in zip(snif_lat,snif_lon,snif_name):
        fg.add_child(folium.Marker(location=[lat,lon],popup=name))

    Mcmap.add_child(fg)
    Mcmap.save("test.html")

然后是结果

enter image description here

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