Python /Plotly/Geopandas

3
我一直遇到这个错误,并看到其他人在网上也遇到了同样的问题。
ImportError: geopandas, pyshp and shapely must be installed for this figure factory.

Run the following commands to install the correct versions of the following modules:

```
pip install geopandas==0.3.0
pip install pyshp==1.2.10
pip install shapely==1.6.3
```
If you are using Windows, follow this post to properly install geopandas and dependencies:http://geoffboeing.com/2014/09/using-geopandas-windows/

If you are using Anaconda, do not use PIP to install the packages above. Instead use conda to install them:

```
conda install plotly

conda install geopanda

事实上,我已经按照以上方法安装了plotly/geopanda,但它仍然无法正常工作。当我单独导入plotly和geopanda时并不会出现错误。事实上,当我对下面的代码进行分析时,发现这行代码ff.create_choropleth是导致错误的原因。以下是完整的代码:
import plotly, geopandas
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
import xlrd
df_sample = pd.read_excel('popdata.xlsx') # Read in your data
values = df_sample['Change'].tolist() # Read in the values contained within your file
fips = df_sample['FIPS'].tolist() # Read in FIPS Codes

colorscale = ["#171c42","#223f78","#1267b2","#4590c4","#8cb5c9","#b6bed5","#dab2be",
              "#d79d8b","#c46852","#a63329","#701b20","#3c0911"]

endpts = list(np.linspace(-75, 75, len(colorscale) - 1)) # Identify a suitable range for your data

#fig = ff.create_choropleth(
  # fips=fips, values=values, colorscale=colorscale, show_state_data=True, binning_endpoints=endpts, # If your values is a list of numbers, you can bin your values into half-open intervals
   # county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, 
   # legend_title='% change', title='% Change in disease between 1980-2014'
#)
py.plot(fig, filename='diseasechange')

你遇到了什么错误?(能否展示完整的回溯信息?) - joris
导入错误。在我的帖子顶部。 - 0004
啊,等我下班回来就会发布追踪信息。 - 0004
2个回答

1
pip install geopandas==0.8.1 

这个问题对我来说已经解决了。


它救了我的一天,非常感谢!我尝试了 traceback 消息中写的所有方法,但都没有帮助,而这个方法却有用。谢谢。 - Ankit Moral

0

不要使用 import plotly figure_factory as ffff.create_choropleth,尝试这样做:

# import necessary libraries
import geopandas
import shapely
import shapefile
import plotly
from plotly.figure_factory._county_choropleth import create_choropleth
import xlrd
# Check your version
print(plotly.__version__, geopandas.__version__,shapely.__version__,shapefile.__version__)
# Data
df_sample = pd.read_excel('popdata.xlsx') # Read in your data
values = df_sample['Change'].tolist() # Read in the values contained within your file
fips = df_sample['FIPS'].tolist() # Read in FIPS Codes

colorscale = ["#171c42","#223f78","#1267b2","#4590c4","#8cb5c9","#b6bed5","#dab2be",
              "#d79d8b","#c46852","#a63329","#701b20","#3c0911"]

endpts = list(np.linspace(-75, 75, len(colorscale) - 1)) # Identify a suitable range for your data

fig = create_choropleth(
   fips=fips, values=values, colorscale=colorscale, show_state_data=True, binning_endpoints=endpts, # If your values is a list of numbers, you can bin your values into half-open intervals
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, 
    legend_title='% change', title='% Change in disease between 1980-2014'
)
# Plot in offline mode and save plot in your Python script folder
plotly.offline.plot(fig, filename='diseasechange.html')

此外,如果您在使用import shapelyimport shapefile时遇到问题,您需要安装它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接