Folium popup gets syntax error message

875 views Asked by At

I'm new to folium. I was able to produce the map I wanted from a dataframe.

df_map = folium.Map(location=[37.750999450684, -97.821998596191], zoom_start=4)   

for each in df[0:len(df)].iterrows(): 
    folium.CircleMarker(location=[each[1]["GEO_LAT_0"], each[1]["GEO_LNG_0"]],
                    radius=5.0, color='#3186cc', fill_color='#3186cc').add_to(df_map)

Map comes out nicely.

Next I wanted to add popups from a third column in data frame, and can't seem to get syntax right. Not clear how I might add these popups from folium documentation. An error message I can't interpret results from this code:

df_map = folium.Map(location=[37.750999450684, -97.821998596191], zoom_start=4)   

for each in df[0:len(df)].iterrows(): 
    folium.CircleMarker(location=[each[1]["GEO_LAT_0"], each[1]["GEO_LNG_0"]],
                    **popup=each[1]["GEO_CITY_0"],**
                    radius=5.0, color='#3186cc',fill_color='#3186cc').add_to(df_map)

To verify my loop and dataframe were ok, I substituted a

print each[1]["GEO_CITY_0"]

within the for-each loop instead of folium.circlemarker and it worked fine. Something is wrong when I use the popup syntax above.

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

Your help appreciated. Thanks p.s. Full message is:

Traceback (most recent call last):

File "", line 4, in radius=1, color='#3186cc', fill_color='#3186cc').add_to(df_map)

File "C:\Users\Peter\Anaconda3\lib\site-packages\folium\features.py", line 870, in init super(CircleMarker, self).init(location=location, popup=popup)

File "C:\Users\Peter\Anaconda3\lib\site-packages\folium\map.py", line 652, in init self.add_child(popup)

File "C:\Users\Peter\Anaconda3\lib\site-packages\branca\element.py", line 96, in add_child name = child.get_name()

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

1

There are 1 answers

2
Bob Haffner On BEST ANSWER

I was under the impression that @pzajonc's syntax of popup=each[1]["GEO_CITY_0"] would work in recent versions (OP's has 0.4.0) of folium.

Here's a github issue that mentions the error and the fix

Regardless, changing it to popup=folium.Popup(each[1]["GEO_CITY_0"]) will resolve the issue.