Created
June 26, 2020 19:08
-
-
Save mbforr/30932097a3cc8a7277352b640a39bb13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| from geopandas import GeoDataFrame, points_from_xy | |
| import geopandas as gpd | |
| import time | |
| # Load the Uber point data | |
| df = pd.read_csv('uber_all.csv') | |
| # Create the GeoDataFrame and assign the proper projection | |
| uber_pickups = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(data.Lon, data.Lat)) | |
| uber_pickups.crs = "EPSG:4326" | |
| # Load the Census Block Group data | |
| block_groups = gpd.read_file('./blockgroups.geojson') | |
| # Perform the spatial join | |
| start = time.time() | |
| joined_data = gpd.sjoin(uber_pickups, block_groups, op='within') | |
| end = time.time() | |
| print(end - start) | |
| # Group the data by Block Group ID and join to the original Block Groups File | |
| grouped = joined_data.groupby('blockgroup').size() | |
| final_data = grouped.to_frame().reset_index() | |
| final_data.columns = ['blockgroup', 'count'] | |
| merged_areas = block_groups.merge(df, on='blockgroup', how='outer') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment