___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 since 2013___
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)
non_motorist = crashes[crashes["valid_lat_long"] & crashes["non-motorist"]]
cols_to_use = [
"LAT",
"LONG",
"DATE",
"TIME",
"INJURED",
"PEDESTRIAN INJURED",
"CYCLIST INJURED",
"KILLED",
"PEDESTRIAN KILLED",
"CYCLIST KILLED",
]
popup_format = (
"'DATE: ' + row[2] + '<br>' +"
"'TIME: ' + row[3] + '<br>' +"
"'TOTAL INJURED: ' + row[4] + '<br>' +"
"'PEDESTRIANS INJURED: ' + row[5] + '<br>' +"
"'CYCLISTS INJURED: ' + row[6] + '<br>' +"
"'TOTAL KILLED: ' + row[7] + '<br>' +"
"'PEDESTRIANS KILLED: ' + row[8] + '<br>' +"
"'CYCLISTS KILLED: ' + row[9]};"
)
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=2020, month=1, day=1)
map_data = non_motorist[non_motorist["datetime"].between(start, end, inclusive="left")][
cols_to_use
]
non_motorist_map = viz.make_marker_map(map_data, popup_format)
non_motorist_map.save(os.path.join(IMG_DIR, "non_motor_map_18_19.html"))
non_motorist_map
start = datetime(year=2020, month=1, day=1)
end = datetime(year=2022, month=1, day=1)
map_data = non_motorist[non_motorist["datetime"].between(start, end, inclusive="left")][
cols_to_use
]
non_motorist_map = viz.make_marker_map(map_data, popup_format)
non_motorist_map.save(os.path.join(IMG_DIR, "non_motor_map_20_21.html"))
non_motorist_map
start = datetime(year=2022, month=1, day=1)
end = datetime(year=2024, month=1, day=1)
map_data = non_motorist[non_motorist["datetime"].between(start, end, inclusive="left")][
cols_to_use
]
non_motorist_map = viz.make_marker_map(map_data, popup_format)
non_motorist_map.save(os.path.join(IMG_DIR, "non_motor_map_22_23.html"))
non_motorist_map