Published
Edited
Feb 14, 2021
Insert cell
Insert cell
Insert cell
Insert cell
dataset.slice(0,2)
Insert cell
Insert cell
dataByBorough = {
const data = d3.rollup(dataset,
collisions => d3.sum(collisions, c => c.injured),
d => d.borough,
d => d3.timeMonth(d.date));
return Array.from(data, ([borough, months]) => ({
borough: borough,
counts: Array.from(months, ([date, injuries]) => ({date: date, injuries}))
}));
}
Insert cell
Insert cell
data = d3.rollup(dataset, collisions => d3.sum(collisions, c => c.injured),
d => d.borough, d => d3.timeMonth(d.date))
Insert cell
Insert cell
data.forEach(function(value, key) {
console.log(key + ' = ' + value);
})
Insert cell
Insert cell
Array.from(data)
Insert cell
Insert cell
[...data]
Insert cell
Insert cell
queens = data.get('QUEENS')
Insert cell
Insert cell
Array.from(queens, ([date, injuries]) => ({date, injuries}))
Insert cell
Insert cell
Insert cell
dataByBorough.map(d => d.borough)
Insert cell
Insert cell
dataByBorough.map(d => d.counts)
Insert cell
Insert cell
dataByBorough[0].counts.map(c => c.date)
Insert cell
Insert cell
dataByBorough.map(d => d.counts.map(c => c.injuries))
Insert cell
Insert cell
dataByBorough.map(d => d.counts.map(c => c.injuries)).flat()
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
import{printTable} from "@uwdata/data-utilities"
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