首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >jupyter notebook在databricks中运行时不显示地理空间图

jupyter notebook在databricks中运行时不显示地理空间图
EN

Stack Overflow用户
提问于 2019-04-08 21:37:13
回答 2查看 252关注 0票数 0

我有一个地理空间打印数据框,并且想要打印它。

我正在开发一个由Databricks运行的Jupyter笔记本电脑。

我下载了一个shapefile (https://data.london.gov.uk/download/statistical-gis-boundary-files-london/9ba8c833-6370-4b11-abdc-314aa020d5e0/statistical-gis-boundaries-london.zip),并设法只对伦敦的一部分进行了子集,使用:

代码语言:javascript
运行
复制
import geopandas as gpd
import descartes
import pandas as pd
import matplotlib.pyplot as plt
fp = '/dbfs/FileStore/tables/LondonShapeFile/OA_2011_London_gen_MHW.shp'
map_df = gpd.read_file(fp, encoding="utf-8")
orp = map_df[map_df['WD11NM_BF']=='Orpington']
print(orp.shape)
orp.plot()

我得到了:

代码语言:javascript
运行
复制
(50, 18)
Out[95]: <matplotlib.axes._subplots.AxesSubplot at 0x7f064e8df5c0>

我没有得到一个图,所以试了一下:

代码语言:javascript
运行
复制
%matplotlib inline

但得到的是:

代码语言:javascript
运行
复制
%matplotlib inline is not supported in Databricks.
You can display matplotlib figures using display(). For an example, see https://docs.databricks.com/user-guide/visualizations/matplotlib-and-ggplot.html

遵循https://docs.databricks.com/user-guide/visualizations/matplotlib-and-ggplot.html works上的建议示例,

代码语言:javascript
运行
复制
import numpy as np
df3 = pd.DataFrame(np.random.randn(1000, 2), columns=['B', 'C']).cumsum()
df3['A'] = pd.Series(list(range(len(df3))))
dd=df3.plot(x='A', y='B')
display(dd.figure)

但是当我尝试用geopandas df实现类似的东西时,我得到了多个错误:

代码语言:javascript
运行
复制
orp.dipslay()
AttributeError: 'GeoDataFrame' object has no attribute 'dipslay'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<command-797544454504214> in <module>()
      1 import descartes
----> 2 orp.dipslay()

/databricks/python/lib/python3.5/site-packages/pandas/core/generic.py in __getattr__(self, name)
   2742             if name in self._info_axis:
   2743                 return self[name]
-> 2744             return object.__getattribute__(self, name)
   2745 
   2746     def __setattr__(self, name, value):

AttributeError: 'GeoDataFrame' object has no attribute 'dipslay'

代码语言:javascript
运行
复制
display(orp)
Exception: Cannot call display(<class 'geopandas.geodataframe.GeoDataFrame'>)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<command-797544454504288> in <module>()
----> 1 display(orp)

/local_disk0/tmp/1553768511027-0/PythonShell.py in display(self, input, *args, **kwargs)
    860             input.help() # This is going to display the help as a side-effect
    861         else:
--> 862             raise Exception(genericErrorMsg)
    863 
    864     def displayHTML(self, html):

Exception: Cannot call display(<class 'geopandas.geodataframe.GeoDataFrame'>)
 Call help(display) for more info.

代码语言:javascript
运行
复制
display(orp.plot())
/databricks/python/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Exception: Cannot call display(<class 'matplotlib.axes._subplots.AxesSubplot'>)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<command-797544454504291> in <module>()
----> 1 display(orp.plot())

/local_disk0/tmp/1553768511027-0/PythonShell.py in display(self, input, *args, **kwargs)
    860             input.help() # This is going to display the help as a side-effect
    861         else:
--> 862             raise Exception(genericErrorMsg)
    863 
    864     def displayHTML(self, html):

Exception: Cannot call display(<class 'matplotlib.axes._subplots.AxesSubplot'>)
 Call help(display) for more info.
EN

回答 2

Stack Overflow用户

发布于 2019-04-08 22:36:07

有些东西在DataBricks中不工作,所以我按照下面的步骤,在我的笔记本电脑(Windows10)上运行它,它工作了。

代码语言:javascript
运行
复制
Windows 10 installation of geopandas
1) I go this website to download the following installation files (.whl):
    https://www.lfd.uci.edu/~gohlke/pythonlibs/
        1.1) Shapely
        1.2) GDAL and
        1.3) Fiona
2) Go to the download file and run in anaconda prompt
     pip install < *.whl>  for Shapely, GDAL and Fiona

票数 0
EN

Stack Overflow用户

发布于 2019-04-08 22:46:26

这个解决方案最终奏效了。

代码语言:javascript
运行
复制
fp = '/dbfs/FileStore/tables/LondonShapeFile/OA_2011_London_gen_MHW.shp'
map_df = gpd.read_file(fp, encoding="utf-8")
print(map_df.shape)
ldn = map_df.plot()
display(ldn.figure)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55574769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档