USA County Choropleth Maps in Python

I have made sure that the required packages have been installed. Yet every time I get this same error.

ImportError Traceback (most recent call last)
in ()
9 values = range(len(fips))
10
—> 11 fig = ff.create_choropleth(fips=fips, values=values)
12 py.iplot(fig, filename=‘choropleth of some cali counties - full usa scope’)

/anaconda3/lib/python3.6/site-packages/plotly/figure_factory/_county_choropleth.py in create_choropleth(fips, values, scope, binning_endpoints, colorscale, order, simplify_county, simplify_state, asp, offline_mode, show_hover, show_state_data, state_outline, county_outline, centroid_marker, round_legend_values, exponent_format, legend_title, **layout_options)
563 if not gp or not shapefile or not shapely:
564 raise ImportError(
–> 565 "geopandas, pyshp and shapely must be installed for this figure "
566 "factory.\n\nRun the following commands in the terminal to "
567 “ensure that the correct versions of the modules are installed:\n”

ImportError: geopandas, pyshp and shapely must be installed for this figure factory.

Run the following commands in the terminal to ensure that the correct versions of the modules are installed:
pip install geopandas==0.3.0
pip install pyshp==1.2.10
pip install shapely==1.6.3

@drissguessous Can you please try installing these packages with pip3 instead of pip? If that does not work, can you please try installing these packages using conda? If using Jupyter notebook, please restart the kernel after installing the packages.

1 Like

If you have Anaconda, do not use pip, i installed with pip and got the same error, installing it with conda solved it.

conda install plotly
conda install geopandas

Run the above two commands and it should work.

Thank you for looking into this and posting a solution.

I will append to the error message to clarify this for other users.

Just letting people know, that these steps don’t in fact correct the issue. I have built a virtual env from scratch and I am experiencing the same issue with modules. I have tried conda, and pip, and pip3. None have worked

1 Like

Hi Justin, I am having the same issue - you ever find a solution?

I was able to solve this problem by installing pyshp using conda (in addition to plotly and geopandas):

conda install pyshp

Then following this example:

https://colab.research.google.com/drive/1T3WgAhyJZBddpAK5z3K3d2laUhH_zgKq#scrollTo=y3Wgapvd4TLc

1 Like

I tried thousands of solutions. This finally worked!