uber / h3-py-notebooks

Jupyter notebooks for h3-py, a hierarchical hexagonal geospatial indexing system
https://h3geo.org/
Apache License 2.0
263 stars 90 forks source link

ValueError: 'left_df' should be GeoDataFrame, got <class 'pandas.core.frame.DataFrame'> #5

Closed phanirithvij closed 3 years ago

phanirithvij commented 3 years ago

There's an error in https://nbviewer.jupyter.org/github/uber/h3-py-notebooks/blob/master/notebooks/unified_data_layers.ipynb

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-6f0a33b43f95> in <module>
     29 plt.title('hex-grid: nyc')
     30 # Intersect Hex Point with CT Polygon
---> 31 df_ct = geopandas.tools.sjoin(gdf, dfh, how="inner")
     32 df_ct.sample(3)
     33 

~/work/h3-py/uber/h3-py-notebooks/env/lib/python3.7/site-packages/geopandas/tools/sjoin.py in sjoin(left_df, right_df, how, op, lsuffix, rsuffix)
     35     if not isinstance(left_df, GeoDataFrame):
     36         raise ValueError(
---> 37             "'left_df' should be GeoDataFrame, got {}".format(type(left_df))
     38         )
     39 

ValueError: 'left_df' should be GeoDataFrame, got <class 'pandas.core.frame.DataFrame'>
phanirithvij commented 3 years ago

In the Load Census Tract Data step

gdf = df.merge(gdf).fillna(0)
gdf.crs = {"init": "epsg:4326"}
gdf.sample(3)

It becomes a pandas DataFrame from GeoDataFrame type need to convert it back to a GeoDataFrame object

Also dfh is a pandas DataFrame.

ajfriend commented 3 years ago

Thanks for spotting this! I'll update this next time I get a chance. Alternatively, if you have a notebook with the fix, I'd be more than happy to merge in a PR. :)