Skip to content

Instantly share code, notes, and snippets.

@tdsmith
Last active December 6, 2023 04:37
Show Gist options
  • Save tdsmith/c19927ef50f6caea7a19ec0a0a26ac36 to your computer and use it in GitHub Desktop.
Save tdsmith/c19927ef50f6caea7a19ec0a0a26ac36 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "61e73113-c589-4c70-9b64-e39d1f858aff",
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dfac2182-f33a-420d-875b-e45168d8ff1c",
"metadata": {},
"outputs": [],
"source": [
"# from https://opendata.vancouver.ca/explore/dataset/public-streets/export/\n",
"df = gpd.read_file(\"public-streets.geojson\").to_crs(epsg=32610)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "963abff8-a71d-4295-927f-1ea1dd785cb4",
"metadata": {},
"outputs": [],
"source": [
"# Strip away street numbers, like 1000 or 100-200\n",
"df[\"street\"] = df.hblock.str.extract(r\"^([\\d-]+ )?(.*$)\")[1]\n",
"df[\"length\"] = df.length"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e0818559-b131-4838-9065-eada86353a46",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"street\n",
"ALDER BAY COURT 22.941218\n",
"HEMLOCK COURT 24.900717\n",
"FOUNTAIN WAY COURT 25.971326\n",
"HALSS CRESCENT 34.813481\n",
"QUILCHENA PLACE 35.288137\n",
"LEG-IN-BOOT SQUARE 36.177284\n",
"SASKATCHEWAN LANE 40.775467\n",
"OLD BRIDGE COURT 42.856889\n",
"TROLLEY PLACE 43.326007\n",
"WORTHINGTON PLACE 44.097867\n",
"STAMP'S LANDING 45.577722\n",
"FALAISE PLACE 46.608327\n",
"KEMPTON PLACE 47.256064\n",
"WALLACE PLACE 48.792139\n",
"FERRY ROW 50.897869\n",
"SUZHOU ALLEY 51.776506\n",
"MUSQUEAM CLOSE 52.783418\n",
"WINLAW PLACE 53.100369\n",
"BRIGHTWOOD PLACE 53.566829\n",
"STIKINE PLACE 54.128494\n",
"BALSAM PLACE 56.954059\n",
"N NOOTKA ST 59.461645\n",
"BONSAI ST 63.725514\n",
"WANETA PLACE 63.856553\n",
"KINGHORNE MEWS 64.538543\n",
"FOUNDRY QUAY 64.871662\n",
"ALDER CROSSING 65.878354\n",
"TYTAHUN CRESCENT 68.858237\n",
"SITKA SQUARE 70.323814\n",
"SAWCUT 72.059733\n",
"BAUER ST 73.562330\n",
"AVERY AV 73.954271\n",
"BERING AV 74.113977\n",
"WEBBER AV 77.083741\n",
"MALTA PLACE 78.008949\n",
"MARKET HILL 79.182129\n",
"GLENGYLE ST 82.478379\n",
"HAILSTONE ST 83.539575\n",
"MEARES AV 86.949007\n",
"KINGS LYNN ST 87.657413\n",
"BUCKETWHEEL 88.753144\n",
"MILTON ST 90.188371\n",
"LANCASTER PLACE 92.332210\n",
"GASTON ST 93.806362\n",
"EDINBURGH ST 94.006466\n",
"N WINDERMERE ST 94.113507\n",
"MOHAWK ST 94.164530\n",
"VALIANT ST 95.002619\n",
"NORTHERN ST 96.445456\n",
"CARIBOO ST 97.492423\n",
"BRAEBURN ST 97.832341\n",
"SASAMAT PLACE 98.959042\n",
"STARBOARD SQUARE 99.104791\n",
"N LAKEWOOD DRIVE 100.458569\n",
"E 67TH AV 100.561387\n",
"ST. CLAIR PLACE 103.018765\n",
"GREER AV 104.565185\n",
"JEANETTE ST 104.943082\n",
"COOK ST 105.545708\n",
"CROWE ST 105.566674\n",
"WYLIE ST 105.571850\n",
"EVELEIGH ST 105.744689\n",
"FREDERICK ST 106.912795\n",
"GATINEAU PLACE 107.222917\n",
"ARBOR AV 107.513218\n",
"MILLYARD 109.153736\n",
"SHAWNEE PLACE 109.566784\n",
"BENTLEY ST 110.611648\n",
"FOLEY ST 111.684360\n",
"COMMERCIAL DIV NORTH 113.986615\n",
"ARBUTUS DIVERSION 114.424397\n",
"ROSE ST 114.685570\n",
"LILY ST 114.707527\n",
"E 66TH AV 115.695036\n",
"SALAL DRIVE 118.461274\n",
"RAND AV 119.174570\n",
"QUEBEC PLACE 119.343894\n",
"COAL HARBOUR QUAY 121.136352\n",
"CEDAR COTTAGE MEWS 121.657503\n",
"W 74TH AV 121.906136\n",
"SHANGHAI ALLEY 123.227790\n",
"WHITHORN COURT 123.453892\n",
"FORGE WALK 124.289303\n",
"BEGG ST 124.451102\n",
"JERICHO CIRCLE 125.915465\n",
"SCANTLINGS 130.272232\n",
"ST. REGIS LANE 130.654644\n",
"GLENDALOUGH PLACE 132.085500\n",
"IVANHOE ST 133.400953\n",
"RAVINE ST 133.783836\n",
"SENLAC ST 134.191056\n",
"MACKENZIE PLACE 134.483900\n",
"CARTIER PLACE 134.734361\n",
"MADDAMS ST 135.963819\n",
"SCALES PLACE 136.012759\n",
"PETERSHAM AV 137.946115\n",
"KULLAHUN DRIVE 138.056440\n",
"SOUTHERN ST 139.653358\n",
"HENNEPIN AV 140.252656\n",
"BELLA-VISTA ST 140.686777\n",
"Name: length, dtype: float64"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with pd.option_context('display.max_rows', 100):\n",
" display(df.groupby(\"street\")[\"length\"].sum().sort_values()[:100])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment