So I’m trying to display a px.choropleth of my March column counts of toxic smell reports, using zip code level data.
My code is as follows:
fig = px.choropleth(
My bndyr_resetIndex looks like this:
Then used the dataframe for my geojson object:
gjsn = bndry.to_json()
I have tried leaving a geographic coordinate system toWGS84, and that still does not work
I think I can help with this.
Without too much context here, my suspicion is that your geojson file is incorrectly setup. Can you post a screenshot of how your gjsn looks like? Is it structured exactly like the following as used in the example?
You drop your geometry column in the bndyr_resetIndex example but I assume you keep them for the geojson for obvious reasons- but the exact structure may not be the same which caused me issues.
I also remember an issue I faced where I needed to convert the geometry data to the crs - did you get your geometry data raw or did you work with shapefiles then converted them to geojson format?
I would also check the little things. Is ZIP a unique identifier in your dataset? That could also cause issues. How about your Mar variable- is that setup as a float/int or is that setup as a string?
Hopefully this helps. Feel free to let me know if this doesn’t. Can help you troubleshoot.
My geometry data was read in as a shapefile actually. It’s format was originally WGS 84 (crs 4289). So essentially I converted them into a geojson format
Hm I see.
I don’t see anything too drastically different aside from the small fact that the id is at the start of your features list rather than at the end in the example.
For the ZIP df column, is that a string? Your zip column might not be being mapped as a result of different data types between the df and geojson.
And are all the values in the ZIP df column unique?
Hmm so it turns out that my ZIP column is an “object” type. I’m assuming that might be it there, and yes, that column contains only unique values.
Well my main concern was that you plotly wasn’t mapping the geojson properly if the geojson showed ZIP as a string while your dataframe had it as a float. But if the object is type: object that should be fine too and not your problem. Is the geojson file just a derivative of the byndr dataframe? In other words, are you certain that every ZIP is present in both the dataframe and the geojson? I think if it can’t map all them properly it won’t show anything.
It is a byproduct, like I mentioned in the beginning of the thread. Its from the bndry.to_jsonn(function)… So both are there. Just realized that the json file you shared did not have strings on both ends of it. Hoe exactly did you create that json file?