How to create Choropleth Map of USA states and DC with own data in Python?

Viewed 257

I have data frame which contains US states and some figures for each state. I have District of Columbia and its data which I need to plot in the map. Plotly Choropleth Map has state which does not have District of Columbia.

plotly.graph_objects..Figure(data=go.Choropleth(
locations=df['statecode'],
z=df['buyers'].astype(float),
locationmode='USA-states',
colorscale='Reds',
autocolorscale=False,
text=df['mytext'], 
marker_line_color='white',
colorbar_title="Total buyers"

))

It has fips which is basically state and its counties, it creates county wise map.

    fips = USA_df['FIPS'].tolist()
    values = df['buyers'].tolist()

    plotly.figure_factory..create_choropleth(
    fips=fips, values=values,
    binning_endpoints=endpts,
    colorscale=colorscale,
    show_state_data=True,
    show_hover=True, centroid_marker={'opacity': 0},
    asp=2.9, title='',
    legend_title='Buyers'
)

So, if I use stateside, Plotly shows map with 50 states and DC is excluded. If I use fips, Plotly shows map for counties and districts.

Is there any way to create the Choropleth USA map for all states and DC?

0 Answers
Related