Reputation: 13
I have a dataframe with zip codes in one column and the number of call center complaints in the other. I'm trying to create a choropleth which should be a simple one, but for some reason it keeps on showing up all gray.
I'm probably making a very simple small error, but I can't locate it. Any help would be appreciated
I have changed types of my data, tried some different key_on options, switched up columns.
!pip install folium
import folium
# create a plain world map
world_map = folium.Map(location=[40.7128, -74.0060], zoom_start=11, tiles='Mapbox Bright')
nyc_geo = r'nyc_zips.json' # geojson file
# generate choropleth map using the total immigration of each country to Canada from 1980 to 2013
world_map.choropleth(
geo_data=nyc_geo,
threshold_scale = [0,5000,10000,15000,20000,25000,30000,35000,40000],
data=df_zip_codes,
columns=['ZipCode', 'Complaints'],
key_on='feature.properties.zips',
fill_color= 'YlOrRd',
fill_opacity=0.5,
line_opacity=0.2,
legend_name='Complaints By Zip Code'
)
# display map
world_map
My dataframe looks like this. 189 rows total. ZipCode and Complaints type(int):
ZipCode Complaints
0 11226 37452
1 10458 35107
2 10467 34272
3 10468 30858
4 10453 30763
5 10452 25279
...
And finally, this is the geoJSON file I am using: http://data.beta.nyc//dataset/3bf5fb73-edb5-4b05-bb29-7c95f4a727fc/resource/6df127b1-6d04-4bb7-b983-07402a2c3f90/download/f4129d9aa6dd4281bc98d0f701629b76nyczipcodetabulationareas.geojson
I don't need this to do much other than be shaded based upon the number of complaints in each zip code. Any assistance would be greatly appreciated.
Upvotes: 0
Views: 724
Reputation: 13
Actually just spotted my mistake. Was using the wrong label for the key_on property. It is postalCode in the geoJSON. Also changed the of my zip code column to string and it is working fine.
Upvotes: 1