question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GeoJsonTooltip on Choropleth showing a pandas column?

See original GitHub issue

I 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'])
)
image

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:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pbowercommented, Jan 28, 2021

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.

1reaction
jtbakercommented, Feb 24, 2019

you were suggesting is use the GeoJson class to create the choropleth

Yep! That will give you more granular control over the styling, highlighting etc. using the style_function, highlight_function, etc. kwargs.

Is there an example notebook on that?

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Text as tooltip, popup or labels in folium choropleth GeoJSON ...
I've had to use folium's GeoJsonTooltip() and some other steps to get this done in the past. I'm curious to know if someone...
Read more >
How to step up your Folium Choropleth Map skills
The first step is to clean the data to plot our Choropleth map. ... If the data is a Pandas DataFrame, the columns...
Read more >
Interactive choropleth with Python and Folium (and some tips)
We need to pass: geo_data: the geopandas dataframe with the geometries; data: the dataframe containing values we want to show in the map...
Read more >
Interactive Choropleth map in Python using Folium - Medium
data: Pandas data frame holding the values needed to show on the choropleth maps. · columns: Columns containing a key and the values...
Read more >
Mapping in Python: Folium - VIA Learning Lab
For example, let's convert the first five rows of the dataframe using the ... We want to create a choropleth map, visualizing the...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found