{
"cells": [
{
"cell_type": "markdown",
"id": "f80b9ce2",
"metadata": {},
"source": [
"# Mapping All Collisions with Pedestrians and Cyclists in NYC\n",
"\n",
"___NYC residents and visitors may be surprised to see how many vehicle collisions injured or killed a pedestrian or cyclist where they live, work, and travel___\n",
"\n",
"### Definitions\n",
"- __Collision:__ A motor vehicle collision involving injuries, deaths, or a significant amount of property damage (~> $1000) reported on a New York State form, MV104-AN\n",
"\n",
"### Data Sources\n",
"\n",
"- Collision data obtained from https://data.cityofnewyork.us/Public-Safety/Motor-Vehicle-Collisions-Crashes/h9gi-nx95\n",
"- Data was processed by running `process_raw.data.py` which saves processed data to local directory specified in `process_raw.data.py` script\n",
"- _Note that \\~10% of collisions are missing lat-long coordinates. These collisions are excluded from the following geographic analyses._"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5eb23132",
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import os.path\n",
"import pandas as pd\n",
"from src import visualizations as viz"
]
},
{
"cell_type": "markdown",
"id": "d07634ca",
"metadata": {},
"source": [
"# Parameters "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "27e5928d",
"metadata": {},
"outputs": [],
"source": [
"PROCESSED_CRASH_DATA = \"data/processed/crashes.pkl\"\n",
"IMG_DIR = \"output/maps\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a23c9b01",
"metadata": {},
"outputs": [],
"source": [
"crashes = pd.read_pickle(PROCESSED_CRASH_DATA)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "db9d3add-ac3a-4990-b211-09d3b6338d47",
"metadata": {},
"outputs": [],
"source": [
"pedestrian = crashes[crashes[\"valid_lat_long\"] & crashes[\"pedestrian\"]]\n",
"cyclist = crashes[crashes[\"valid_lat_long\"] & crashes[\"cyclist\"]]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "bd0de749-af7d-4a91-a3f3-083d752cd9b9",
"metadata": {},
"outputs": [],
"source": [
"pedestrian_cols = [\n",
" \"LAT\",\n",
" \"LONG\",\n",
" \"DATE\",\n",
" \"TIME\",\n",
" \"PEDESTRIAN INJURED\",\n",
" \"PEDESTRIAN KILLED\",\n",
"]\n",
"pedestrian_format = (\n",
" \"'DATE: ' + row[2] + '
' +\"\n",
" \"'TIME: ' + row[3] + '
' +\"\n",
" \"'PEDESTRIANS INJURED: ' + row[4] + '
' +\"\n",
" \"'PEDESTRIANS KILLED: ' + row[5]};\"\n",
")\n",
"cyclist_cols = [\n",
" \"LAT\",\n",
" \"LONG\",\n",
" \"DATE\",\n",
" \"TIME\",\n",
" \"CYCLIST INJURED\",\n",
" \"CYCLIST KILLED\",\n",
"]\n",
"cyclist_format = (\n",
" \"'DATE: ' + row[2] + '
' +\"\n",
" \"'TIME: ' + row[3] + '
' +\"\n",
" \"'CYCLISTS INJURED: ' + row[4] + '
' +\"\n",
" \"'CYCLISTS KILLED: ' + row[5]};\"\n",
")"
]
},
{
"cell_type": "markdown",
"id": "fdcf9b45",
"metadata": {},
"source": [
"# Map of all Collisions with Pedestrians 2018 - 2023 (inclusive)\n",
"\n",
"_Zoom in to see serious collisions and the date, time, number injured, and number killed_"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c5e319f2-4942-4c79-a93b-7ccc1f07045f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"