___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___
process_raw.data.py
which saves processed data to local directory specified in process_raw.data.py
scriptfrom datetime import datetime
import os.path
import pandas as pd
from src import visualizations as viz
PROCESSED_CRASH_DATA = "data/processed/crashes.pkl"
IMG_DIR = "output/maps"
crashes = pd.read_pickle(PROCESSED_CRASH_DATA)
pedestrian = crashes[crashes["valid_lat_long"] & crashes["pedestrian"]]
cyclist = crashes[crashes["valid_lat_long"] & crashes["cyclist"]]
pedestrian_cols = [
"LAT",
"LONG",
"DATE",
"TIME",
"PEDESTRIAN INJURED",
"PEDESTRIAN KILLED",
]
pedestrian_format = (
"'DATE: ' + row[2] + '<br>' +"
"'TIME: ' + row[3] + '<br>' +"
"'PEDESTRIANS INJURED: ' + row[4] + '<br>' +"
"'PEDESTRIANS KILLED: ' + row[5]};"
)
cyclist_cols = [
"LAT",
"LONG",
"DATE",
"TIME",
"CYCLIST INJURED",
"CYCLIST KILLED",
]
cyclist_format = (
"'DATE: ' + row[2] + '<br>' +"
"'TIME: ' + row[3] + '<br>' +"
"'CYCLISTS INJURED: ' + row[4] + '<br>' +"
"'CYCLISTS KILLED: ' + row[5]};"
)
Zoom in to see serious collisions and the date, time, number injured, and number killed
start = datetime(year=2018, month=1, day=1)
end = datetime(year=2024, month=1, day=1)
map_data = pedestrian[pedestrian["datetime"].between(start, end, inclusive="left")][
pedestrian_cols
]
pedestrian_map = viz.make_marker_map(map_data, pedestrian_format)
pedestrian_map.save(os.path.join(IMG_DIR, "pedestrian_map_18_23.html"))
pedestrian_map
Zoom in to see serious collisions and the date, time, number injured, and number killed
start = datetime(year=2018, month=1, day=1)
end = datetime(year=2024, month=1, day=1)
map_data = cyclist[cyclist["datetime"].between(start, end, inclusive="left")][
cyclist_cols
]
cyclist_map = viz.make_marker_map(map_data, cyclist_format)
cyclist_map.save(os.path.join(IMG_DIR, "cyclist_map_18_23.html"))
cyclist_map