I have a geo json file that gives data about political districts in PA (state in USA): api='https://www.redistricting.state.pa.us/Resources/GISData/Districts/Legislative/House/2021-Final/JSON/2022%20LRC-House-Final.json'
I have dataset that looks smth like this:
| |District|Total Population|...|
|---|--------|----------------|---|
|0 |1 |35000 |...|
|1 |2 |67800 |...|
|2 |3 |93300 |...|
|...|... |... |...|
Json file and dataset can be connected by 'District' variable in both (df['District'] in dataset, and ['properties']['District'] in json)
I need to produce map that draws polygons of districts in PA based on coordinates given in json file in ['geometry'], and shows total population of those districts from the data given in df
Here is what I tried:
with urlopen(api) as response:
geo = json.load(response)
districts_geo=[]
for district in geo['features']:
district_no=district['properties']['District']
geometry=district['geometry']
districts_geo.append({
'type':'Feature',
'geometry':geometry,
'id':district_no
})
districts_geo_ok={'type':'FeatureCollection','features':districts_geo}
fig=px.choropleth(df, geojson=districts_geo_ok, scope='usa' ,locations='District', color='Total population')
fig.update_geos(fitbounds="locations", visible=False)
fig.show()

