New task was created
Get folium data in right format for choropleth map
Created on Monday 2 November 2020, 13:30
Back to task list-
ID331862
-
ProjectMetabolism of Cities
-
StatusCompleted
-
PriorityMedium
-
TypeProgramming work
-
Assigned toPaul Hoekman
-
SubscribersGuus HoekmanPaul Hoekman
Description
In order to make a choropleth map with folium the data needs to be in a specific format.
https://python-visualization.github.io/folium/quickstart.html#Choropleth-maps
The example from there:
url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
state_geo = f'{url}/us-states.json'
state_unemployment = f'{url}/US_Unemployment_Oct2012.csv'
state_data = pd.read_csv(state_unemployment)
The state_geo
part is fine, that's just a geojson like we already have.
They use pandas to read the csv of the data. That's a very simple CSV.
Later on the map is generated like this:
folium.Choropleth(
geo_data=state_geo,
name='choropleth',
data=state_data,
columns=['State', 'Unemployment'],
key_on='feature.id',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Unemployment Rate (%)'
).add_to(m)
So the key parts for this work is columns
(which defines which columns are taken into consideration) and key_on
(which is the place where the geojson features match the first column of the dataset).
They started with CSV so used pandas, but I don't think that's necessary. We just need the same output.