3

我对 folium 很陌生,并且试图通过循环遍历包含坐标对和每对位置名称的熊猫AttributeError来向地图添加一系列标记,例如foliumdf

   location_name  location  
   'foo'          [40.736932, -73.997043]   
   'bar'          [40.738859, -73.995058]   
   'xyz'          [40.744085, -74.000394]

使用以下代码:

center_map = [40.738859, -73.995058]

map_1 = folium.Map(location=center_map, tiles=None, zoom_start=12)

for i in df:
        folium.Marker(i.location,
                      popup=i.location_name,
                      icon=folium.Icon(color='purple')
                      ).add_to(map_1)

但是,我收到以下错误:

AttributeError: 'Series' object has no attribute 'get_name'

我认为是由element.pygeneric.py文件引起的folium

/Users/martin/anaconda/envs/py3k/lib/python3.5/site-packages/folium/element.py in add_children(self, child, name, index)
     85     def add_children(self, child, name=None, index=None):
     86         """Add a child."""
---> 87         return self.add_child(child, name=name, index=index)
     88 
     89     def add_child(self, child, name=None, index=None):

/Users/martin/anaconda/envs/py3k/lib/python3.5/site-packages/folium/element.py in add_child(self, child, name, index)
     90         """Add a child."""
     91         if name is None:
---> 92             name = child.get_name()
     93         if index is None:
     94             self._children[name] = child

/Users/martin/anaconda/envs/py3k/lib/python3.5/site-packages/pandas/core/generic.py in __getattr__(self, name)
   2667             if name in self._info_axis:
   2668                 return self[name]
-> 2669             return object.__getattribute__(self, name)
   2670 
   2671     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'get_name'

感谢有关如何解决此问题的任何帮助!

4

1 回答 1

5

迟到总比不到好!在相同的错误代码之后到达这里,我忘记调用 folium.Popup(details) 我想这就是需要的孩子。

此行引起的错误

popup=i.location_name

应该是

popup = folium.Popup(i.location_name)
于 2018-11-08T15:19:26.300 回答