Issue
I'm trying to show the 'total_yearly_compensation' and 'base_salary' for tech jobs within the United States. I've been working on this for awhile and can't seem to find why the US-States map only is grey instead of the colors it should be showing. My code is below.
Here is all of the imports that I'm bringing in and a glimpse of my CSV file:
Here is a screenshot of what my us-states.json file looks like:
And this is how I'm trying to create the Folium Choropleth map (also showing the grey US map):
I greatly appreciate any help!
Solution
You need to have the name of the location column in the parameter columns
of the Choropleth()
function. Moreover, you need to have exactly the same values in the location column and in the JSON file (you can create an id
column from the location
column). You can update your code like that :
df_sal[["city", "id"]] = df_sal["location"].str.split(", ", expand=True)
folium.Choropleth(
geo_data = country_geo,
data = data_to_plot,
columns = ['id', 'total_yearly_compensation', 'base_salary'],
key_on = 'feature.id',
).add_to(map)
Answered By - Pierre-Loic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.