Published
Edited
Aug 18, 2022
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"}) //viewing data in table format
Insert cell
Insert cell
Insert cell
mon = ({ 0:'jan',1:'feb',2:'mar',3:'apr',4:'may',5:'june',6:'jul',7:'aug',8:'sep',9:'oct',10:'nov',11:'dec'})
Insert cell
d3.rollup(
data,
group=>group.length,
d=>mon[d.dateTime.getMonth()]
)
// we can see the months May, June, and July have more collisions
Insert cell
Insert cell
d3.rollup(
data,
group=>d3.sum(group,d=> d.injured + d.killed),
d=>mon[d.dateTime.getMonth()] //again in the months of june, may, july deaths and injuries are more/higher
)
Insert cell
Insert cell
Insert cell
md`What are the Top 5 zipcodes with highest number of collisions?.`
Insert cell

collision = data.filter(d => d.zip !== '')
Insert cell
d3.groupSort(collision,
group=>group.length,
d=>d.zip).reverse().slice(0,5) // top 5 with highest no. of collisons
Insert cell
md`What are the Top 5 zipcodes with highest number of injuries and deaths?.`

Insert cell
d3.rollup(collision,
group => d3.sum(group, d=> d.killed + d.injured),
d => d.zip) //showing no. of injuries and death for all zipcodes
Insert cell
d3.groupSort(collision,
group => d3.sum(group, d=> d.killed + d.injured),
d => d.zip).reverse()
.slice(0,5) // top 5 zipcodes with highest injury and death
Insert cell
Insert cell
md`What are the Top 5 causes that contributed highest number of collisions?`
Insert cell
d3.groupSort(
data,
group => group.length,
d => d.cause
).reverse()
.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