Why is my geopandas installation missing sjoin? AttributeError: 'GeoDataFrame' object has no attribute 'sjoin'

Viewed 2534

I need to use geopandas sjoin on a project. I have successfully created GeoDataFrame objects and used class methods readfile, crs and to_crs. However when it comes to using sjoin I am getting an error: AttributeError: 'GeoDataFrame' object has no attribute 'sjoin'.

So I thought I would attempt to get sjoin working on a simple example taken directly from the official geopandas website: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.sjoin.html

import geopandas

countries = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
cities = geopandas.read_file(geopandas.datasets.get_path("naturalearth_cities"))
print(countries.head())
print(cities.head())

cities_w_country_data = cities.sjoin(countries)
print(cities_w_country_data.head())

Yet I am encountering the same problem. Please could someone explain this error and offer a solution? Thanks.

The output is as follows:

C:\Users\mmm\AppData\Local\ESRI\conda\envs\arcgispro-py3_clone\lib\site-packages\geopandas\array.py:85: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
  aout[:] = out
C:\Users\mmm\AppData\Local\ESRI\conda\envs\arcgispro-py3_clone\lib\site-packages\geopandas\geodataframe.py:35: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.
  out = from_shapely(data)
     pop_est      continent  ...  gdp_md_est                                           geometry
0     920938        Oceania  ...      8374.0  MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1   53950935         Africa  ...    150600.0  POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2     603253         Africa  ...       906.5  POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3   35623680  North America  ...   1674000.0  MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4  326625791  North America  ...  18560000.0  MULTIPOLYGON (((-122.84000 49.00000, -120.0000...

[5 rows x 6 columns]
           name                   geometry
0  Vatican City  POINT (12.45339 41.90328)
1    San Marino  POINT (12.44177 43.93610)
2         Vaduz   POINT (9.51667 47.13372)
3    Luxembourg   POINT (6.13000 49.61166)
4       Palikir  POINT (158.14997 6.91664)
Traceback (most recent call last):
  File "geopandas_sjoin_official_eg.py", line 8, in <module>
    cities_w_country_data = cities.sjoin(countries)
  File "C:\Users\mmm\AppData\Local\ESRI\conda\envs\arcgispro-py3_clone\lib\site-packages\pandas\core\generic.py", line 5465, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'GeoDataFrame' object has no attribute 'sjoin'

Note: I am using Windows 10. I am running my code from within a cloned ArcGIS Pro Conda environment. I recently installed geopandas using the command "conda install geopandas -y"

0 Answers
Related