Public
Edited
Feb 10
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = d3.csv(url, crash => ({
// combine the date and time strings into one Date object
dateTime: d3.timeParse('%m/%d/%Y %H:%M')(crash.date + ' ' + crash.time),
borough: crash.borough,
zip: crash.zip,
injured: +crash.injured, // + converts the string to an int
killed: +crash.killed,
cause: crash.cause
}))
Insert cell
Inputs.table(data, {columns: ["dateTime", "borough", "zip", "injured", "killed", "cause"], layout: "auto"})
Insert cell
Insert cell
md`How did the number of injuries in NYC vary across the hours of the day in 2019.`
Insert cell
injuriesByHour = d3.rollup(data, v => d3.sum(v, d => d.injured), d => d.dateTime.getHours())
Insert cell
Insert cell
Insert cell
md`Which boroughs experience the highest number of collision-related deaths.`
Insert cell
borough_deaths = data.filter(d => d.borough && d.borough !== "");
Insert cell
deathsByBorough = d3.rollup( borough_deaths, v => d3.sum(v, d => d.killed), d => d.borough);
Insert cell
Insert cell
md`What are the three highest causes of collicions in New York City?`
Insert cell
collisionsByCause = d3.rollup(
data,
v => v.length,
d => d.cause
);
Insert cell
causesData = Array.from(collisionsByCause, ([cause, count]) => ({ cause, count }));
Insert cell
causesData.sort((a, b) => d3.descending(a.count, b.count));
Insert cell
topCauses = causesData.slice(0, 3);
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more