I am using folium to create a map and plot latitude and longitude points in a dataframe in that. This is my code:
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)
This is the error I get:
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'
But I am able to see the map if I just view the map. Just that I am unable to plot the latitude and longitude points in that.
Have you tried using a loop to add one marker at a time? In the folium documentation, they didn't mention you can add a list of markers at once.