Choropleth map using ONLY geojson (no associated dataframe)

Is it possible to do a choropleth map using only the geojson and not an associated dataframe?

My data is packaged inside the properties of the geojson. I can loop through and extract it, but this seems like extra work and the figure should be able to handle using the geojson for both the geometry and values. But am not sure how to do this - anyone know?

like this?

from urllib.request import urlopen
import json
with urlopen('') as response:
    counties = json.load(response)

import pandas as pd
df = pd.read_csv("",
                   dtype={"fips": str})

import as px

fig = px.choropleth_mapbox(df, geojson=counties, locations='fips', color='unemp',
                           range_color=(0, 12),
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           labels={'unemp':'unemployment rate'}

That case is using the “fips-unemp-16.csv” as the source of the value for the choropleth.

What I want is this situation, but where the source of the unemployment data is a properties value in the geojson itself.

So for example if the county geojson looked like this [I added the UNEMP to the geojson dictionary]:

{'type': 'Feature',
 'properties': {'GEO_ID': '0500000US01001',
  'STATE': '01',
  'COUNTY': '001',
  'NAME': 'Autauga',
  'LSAD': 'County',
  **'UNEMP': 5.3,**
  'CENSUSAREA': 594.436},
 'geometry': {'type': 'Polygon',
  'coordinates': [[[-86.496774, 32.344437],
    [-86.717897, 32.402814],
    [-86.814912, 32.340803],
    [-86.890581, 32.502974],
    [-86.917595, 32.664169],
    [-86.71339, 32.661732],
    [-86.714219, 32.705694],
    [-86.413116, 32.707386],
    [-86.411172, 32.409937],
    [-86.496774, 32.344437]]]},
 'id': '01001'}

I am currently loading the geojson, looping through to strip out the properties to create a dataframe, and then putting it into the code as demonstrated. But this seems fairly inefficient. What I am wondering is if there is a setup that feeds the data / location info directly from the geojson rather than merging the geojson onto a dataframe.

Or another example - if you have the counties for geojson and you want to use the CENSUSAREA value for the choropleth. Do you need to extract this into a dataframe to make it work, or is there a way to skip that step.

Can the geopandas library reduce your workload?

Hi @nicolaskruchten, all the use cases I’ve seen seem to include a pd dataframe. Could you please take a look at this?

geopandas may be the answer they want for these situations: convert geojson → geopandas then use that.

Thanks for mentioning. Had somehow skipped over that section of the documentation.