我正在使用 folium 创建地图并在其中的数据框中绘制纬度和经度点。这是我的代码:
import pandas as pd
import folium
lats =[]
lons =[]
texts=[]
for each in df1[0:len(df1)].iterrows():
lat = each [1]['pickup_lat']
lats.append(lat)
lon = each [1]['pickup_lon']
lons.append(lon)
text= each[1]['vehicle_type']
texts.append(text)
locations = list(zip(lats,lons))
map = folium.Map(location =[df1['pickup_lat'].mean(),df1['pickup_lon'].mean()],zoom_start =13)
folium.CircleMarker(location=locations ,radius=5,popup=texts).add_to(map)
这是我得到的错误:
AttributeError Traceback (most recent call last)
<ipython-input-226-02aa653c3cd6> in <module>()
16
17 map = folium.Map(location =[df1['pickup_lat'].mean(),df1['pickup_lon'].mean()],zoom_start =13)
---> 18 folium.CircleMarker(location=locations ,radius=5,popup=texts).add_to(map)
C:\Users\Harikrishna\Anaconda3\lib\site-packages\folium\features.py in __init__(self, location, radius, color, weight, fill_color, fill_opacity, popup)
765 weight=2, fill_color='black', fill_opacity=0.6,
766 popup=None):
--> 767 super(CircleMarker, self).__init__(location, popup=popup)
768 self._name = 'CircleMarker'
769 self.radius = radius
C:\Users\Harikrishna\Anaconda3\lib\site-packages\folium\map.py in __init__(self, location, popup, icon)
612 self.add_child(Popup(popup))
613 elif popup is not None:
--> 614 self.add_child(popup)
615
616 self._template = Template(u"""
C:\Users\Harikrishna\Anaconda3\lib\site-packages\branca\element.py in add_child(self, child, name, index)
94 """Add a child."""
95 if name is None:
---> 96 name = child.get_name()
97 if index is None:
98 self._children[name] = child
AttributeError: 'list' object has no attribute 'get_name'
但如果我只看地图,我就能看到地图。只是我无法在其中绘制纬度和经度点。