Public
Edited
Feb 3
17 forks
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
Insert cell
Insert cell
// Write the code here
d3.mean(data, d => d.injured + d.killed)

Insert cell
Insert cell
// Write the code here
d3.rollup(
data,
g=> g.length,
d => d.dateTime.getDate()
)
Insert cell
Insert cell
// Write the code here
data.filter(d => d.zip === "").length
Insert cell
Insert cell
// Write the code here
new Set(data.map(d => d.zip)).size
Insert cell
Insert cell
// Write the code here
d3.max(data, d => d.injured)
Insert cell
Insert cell
// Write the code here
d3.groupSort(data, g => g.length, collision => collision.borough).filter(borough => borough !== "").reverse()
Insert cell
Insert cell
// Write the code here
zip11201 = data.filter(collision => collision.zip === '11201')
Insert cell
Insert cell
// Write the code here
zip11201.map(collision => collision.cause)
Insert cell
Insert cell
// Write the code here
data.toSorted((a, b) => d3.descending(a.injured, b.injured)).slice(0, 5)
Insert cell
Insert cell
What are the top 10 zip codes with highest collisions?
Insert cell
// Write the code to get the data here
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