I need to extract all unique values from the "CATEGORIES" column from shapefile 2 (from the Shapefile and its data frame is shown below)
Shapefile-B Shapefile-B Data Table first 5 rows

and add them as columns to the Shapefile-A data table (see shapefile and its DataFrame below). Shapefile-A (US Blocks) Shapefile-A Data Table first 5 rows

And then I need to sum points in each polygon. The final table from this spatial join should look similar "Fig-Final Result".

Final Result

How can I accomplish this using pandas or another geospatial library (except arcpy) in python?

  • What is your question exactly? – joris Nov 20 '18 at 19:15
  • I just updated my question. Kindly check it. – Vijay Bendigeri Nov 20 '18 at 19:36

I would think you could simply do something like:

import geopandas as gpd    
blocks_with_points = gpd.sjoin(blocks_1, poi_2, how="inner", op='intersects')

And then do a pandas crosstab:

result = pd.crosstab(index=blocks_with_points['blockid10'], 

You could also try using the built-in dummy variable method and concatenating. Since Geopandas is an extension of pandas I assume it has get_dummies...

X = gpd.GeoDataFrame(pd.concat([X, pd.get_dummies(X['categories'])], axis = 1), geometry = ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.