首页 > 解决方案 > AttributeError:在 geopandas 中绘图时,“PandasArray”对象没有属性“_str_startswith”

问题描述

我不得不重新设置我的 python 环境并收到以下错误消息:

AttributeError:“PandasArray”对象没有属性“_str_startswith”

当我尝试使用基本的 GeoDataFrame.plot() 函数时

geoDF= geopandas.readfile('myfile.geojson')
geoDF.plot()

我已经更新了 pandas、matplotlib、numpy、geopandas,但仍然遇到同样的问题。

~\anaconda3\lib\site-packages\geopandas\geodataframe.py in plot(self, *args, **kwargs)
    919         from there.
    920         """
--> 921         return plot_dataframe(self, *args, **kwargs)
    922 
    923     plot.__doc__ = plot_dataframe.__doc__

~\anaconda3\lib\site-packages\geopandas\plotting.py in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
    613 
    614     if column is None:
--> 615         return plot_series(
    616             df.geometry,
    617             cmap=cmap,

~\anaconda3\lib\site-packages\geopandas\plotting.py in plot_series(s, cmap, color, ax, figsize, aspect, **style_kwds)
    388 
    389     # decompose GeometryCollections
--> 390     geoms, multiindex = _flatten_multi_geoms(s.geometry, prefix="Geom")
    391     values = np.take(values, multiindex, axis=0) if cmap else None
    392     expl_series = geopandas.GeoSeries(geoms)

~\anaconda3\lib\site-packages\geopandas\plotting.py in _flatten_multi_geoms(geoms, prefix)
     42     components, component_index = [], []
     43 
---> 44     if not geoms.geom_type.str.startswith(prefix).any():
     45         return geoms, np.arange(len(geoms))
     46 
~\anaconda3\lib\site-packages\pandas\core\strings\accessor.py in wrapper(self, *args, **kwargs)
     99                 )
    100                 raise TypeError(msg)
--> 101             return func(self, *args, **kwargs)
    102 
    103         wrapper.__name__ = func_name
~\anaconda3\lib\site-packages\pandas\core\strings\accessor.py in startswith(self, pat, na)
   2070         dtype: bool
   2071         """
-> 2072         result = self._array._str_startswith(pat, na=na)
   2073         return self._wrap_result(result, returns_string=False)
   2074 

AttributeError: 'PandasArray' object has no attribute '_str_startswith'

谢谢!

标签: pythonpandasplotgeopandas

解决方案


已经解决了!必须将 pandas 更新到 1.2.0 版本,然后安装笛卡尔包。


推荐阅读