GeoJsonTooltip on Choropleth showing a pandas column?
See original GitHub issueI want to have a tooltip on my Choropleth to show the actual value of a region. Specifically Im making a choropleth of Amsterdam with the count of customers in a certain postal code.
density = (df
.reset_index()
.rename(columns={'Id': 'Count'})
.groupby('Postcode cijfers')
.count()
)[['Count']].reset_index()
# Postcode cijfers, Count
# array([['1011', 213],
# ['1012', 146],
# ['1013', 402],
# ['1014', 49],
# ['1015', 354]], dtype=object)
m = folium.Map(location=(52.3740300, 4.8896900),
min_zoom=11)
choropleth = folium.Choropleth('../Resources/PC4_BUURTEN.json',
name='Postal Codes',
data=density,
key_on='properties.Postcode4',
columns=['Postcode cijfers', 'Count'],
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Customer Count',
).add_to(m)
choropleth.geojson.add_child(
folium.features.GeoJsonTooltip(['Postcode4'])
)
Problem description
The documentation states:
fields (list or tuple.) – Labels of GeoJson/TopoJson ‘properties’ or GeoPandas GeoDataFrame columns you’d like to display.
However when I try to add Count
to the fields (GeoJsonTooltip(['Postcode4', 'Count'])
) I get the following error:
AssertionError: The field Count is not available in the data. Choose from: ('Postcode4', 'Opp_m2').
Suggesting that it only looks to the GeoJSON properties list.
Question
How can I refer to the attached dataframe for showing the Count
in the tooltip? Is there a possibility for this, or is the documentation wrong / did I misunderstood it?
In the mean time I could iterate over the GeoJSON and manually add the Count
field to the properties.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Is this something that can be re-considered? As a user it’s really annoying to have to bounce this data back to the GeoJSON data structure instead of the convenience of using a pandas column.
Yep! That will give you more granular control over the styling, highlighting etc. using the
style_function
,highlight_function
, etc. kwargs.Check the examples repository on NBViewer for some examples on how to those and other features of the library. The
Plugin-search.ipynb
notebook has a good example for your usage, likely.