Search code examples
pythonplotlychoropleth

Plotly choropleth not working as expected


I am trying to understand why no data is showing up on a plotly choropleth map

The full code is in this kaggle notebook

I am trying to graph some summary data by state using a choropleth map with Plotly Express. I've recreated the problem in the notebook above using county-level population data from the US Census Bureau.

The raw data has multiple entries per state, which I am using groupby to summarize by state.

 df = df_raw.groupby('State')['Population'].agg(['count','sum','mean','median','max','min']).reset_index()

Then graphing it with plotly

fig = px.choropleth(
    df,
    locations='State',
    color = 'sum',  
    locationmode='USA-states',
    scope='usa'
)
fig.show()

The chart renders and the scale to the right is scaled properly, but there is no color fill in the state shapes.

enter image description here


Solution

  • Remove spaces in names of states:

    df['State'] = df['State'].str.strip()
    

    Hope that helps!