Public
Edited
Aug 13, 2022
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 ? crash.zip : 'no',
zipcode: crash.zip == "" ? 'no' : 'yes',
injured: +crash.injured, // + converts the string to an int
killed: +crash.killed,
cause: crash.cause

}))
Insert cell
Inputs.table(data, {columns: ["dateTime", "borough", "zip", "zipcode", "injured", "killed", "cause"], layout: "auto"})
Insert cell
Insert cell
injure = d3.mean(data, d => d.injured)
Insert cell
killed = d3.mean(data, d => d.killed + d.injured)
Insert cell
data.length
Insert cell
Insert cell
d3.rollup(data, g => g.length , d => d.dateTime.getDate())
Insert cell
Insert cell
d3.flatRollup(data, g => g.length, d => d.zipcode)
Insert cell
Insert cell
[...new Set(data.map(d => d.zip))].length
Insert cell
Insert cell
d3.max(data, d => d.injured)
Insert cell
d3.max(data, d => d.killed)
Insert cell
Insert cell
d3.rollups(data, g => d3.sum(g, inp => inp.injured), d => d.borough)
.sort((a,b) => d3.descending(a[1], b[1]))
Insert cell
Insert cell
data.filter(d => d.zip == "11201")
Insert cell
Insert cell
data.filter(d => d.zip == "11201").map(d => d.cause)
Insert cell
Insert cell
data.sort((a,b) => d3.descending(a.injured, b.injured)).slice(0,5)
Insert cell
Insert cell
md`Which Zip codes in NYC have highest number of collisions`
Insert cell
d3.rollups(data, g => g.length, d=> d.zip)
.sort((a, b) => d3.descending(a[1], b[1]))
.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