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
Insert cell
Insert cell
monthlyCollisionChanges = d3.rollups(
data,
group => ({
totalCollisions: group.length,
totalInjuries: d3.sum(group, d => d.injured),
totalFatalities: d3.sum(group, d=> d.killed)
}),
d => d3.timeFormat("%Y-%m")(d.dateTime)
)
.map(([month, values]) => ({month, ...values}))
.sort((a,b) => d3.ascending(a.month, b.month))
Insert cell
Insert cell
Insert cell
Insert cell
collisionsWithZip = data.filter(d => d.zip !== "")
Insert cell
topInjuryFatalityZipCodes = d3.rollups(
collisionsWithZip,
group => ({
totalCasualties: d3.sum(group, d=> d.injured + d.killed)
}),
d => d.zip
)
.map(([zip, values]) => ({zip, totalCasualties: values. totalCasualties}))
.sort((a, b) => d3.descending(a.totalCasualties, b.totalCasualties))
.slice(0, 5);
Insert cell
Insert cell
Insert cell
CollisionCausesCount = d3.rollups(
data,
group => ({
count: group.length
}),
d => d.cause
)
.map(([cause, values]) => ({cause, count: values.count}))
Insert cell
top5CollisionCauses = CollisionCausesCount.sort((a,b) => d3.descending(a.count, b.count)).slice(0,5)
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