I am trying to make a choropleth map using data stored in a '.csv' over a '.geojson' polygon map. The geojson map is apparently rendering properly, but the colors from the values in the data.csv aren't showing up at all. I am new using folium and after reading the whole documentation I can't still figure out what I am doing wrong! I have posted the jupyter notebook and all data in a github repository.
I am working in a conda environment using folium '0.5.0'
Thanks in advance!
import pandas as pd
import folium
import json
import os
regiones_data = os.path.join('regiones.csv')
regiones_geo = os.path.join('regiones.geojson')
data = pd.read_csv(regiones_data, na_values=[' '])
data.info()
m = folium.Map(
location=[-37.807973, -71.894346],
tiles='Mapbox Bright',
zoom_start=4,
control_scale=True
)
m.choropleth(
geo_data=regiones_geo,
name='choropleth',
data=data,
columns=['region_id', 'votos_tricel'],
key_on='feature.properties.region_id',
fill_color='BuPu',
fill_opacity=.7,
line_opacity=.5,
highlight=True,
legend_name='Numero Total de Votos',
reset=True
)
folium.LayerControl().add_to(m)
m
you're not adding the choropleth to the map
On Sun, Jul 22, 2018, 12:09 Mauricio Cifuentes Navarro <
[email protected]> wrote:
I am trying to make a choropleth map using data stored in a '.csv' over
a '.geojson' polygon map. The geojson map is apparently rendering
properly, but the colors from the values in the data.csv aren't showing up
at all. I am new using folium and after reading the whole documentation I
can't still figure out what I am doing wrong! I have posted the jupyter
notebook and all data in a github repository.I am working in a conda environment using folium '0.5.0'
Thanks in advance!
https://github.com/transluciddata/folium_problem
https://nbviewer.jupyter.org/github/transluciddata/folium_problem/blob/master/prueba.ipynbimport pandas as pdimport foliumimport jsonimport os
regiones_data = os.path.join('regiones.csv')
regiones_geo = os.path.join('regiones.geojson')data = pd.read_csv(regiones_data, na_values=[' '])
data.info()m = folium.Map(
location=[-37.807973, -71.894346],
tiles='Mapbox Bright',
zoom_start=4,
control_scale=True
)m.choropleth(
geo_data=regiones_geo,
name='choropleth',
data=data,
columns=['region_id', 'votos_tricel'],
key_on='feature.properties.region_id',
fill_color='BuPu',
fill_opacity=.7,
line_opacity=.5,
highlight=True,
legend_name='Numero Total de Votos',
reset=True
)folium.LayerControl().add_to(m)
m
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/python-visualization/folium/issues/917, or mute the
thread
https://github.com/notifications/unsubscribe-auth/AGzdufIVjD2d0uwiDvnORx_MUJ2HM53Eks5uJKOegaJpZM4VaDPG
.
The problem is with the region_ids in your geojson. Their values are strings, but in the csv they are ints. If you change the values in the geojson to ints it works:
"region_id": "2"
becomes
"region_id": 2
We should add checks on the input data and raise errors when they don't match. I opened up a separate issue for this, if you want to contribute to this you're welcome to!
Thanks for that @Conengmo !
Thank you very much @Conengmo !
@Conengmo Is there a way to do this automatically? I mean, without change the values one by one in the json file.
The problem is with the region_ids in your geojson. Their values are strings, but in the csv they are ints. If you change the values in the geojson to ints it works:
"region_id": "2"becomes
"region_id": 2
We got a PR in the make to do this automatically: https://github.com/python-visualization/folium/pull/1193
Most helpful comment
The problem is with the region_ids in your geojson. Their values are strings, but in the csv they are ints. If you change the values in the geojson to ints it works:
"region_id": "2"becomes
"region_id": 2