Published unlisted
Edited
Mar 8, 2021
Insert cell
Insert cell
// Load the data with the Date column
protests = aq.fromCSV(await FileAttachment("protests.csv").text())
Insert cell
Insert cell
// Add monthNames as a table param
protests
.params({ monthNames }) // add the parameter
.derive({ month: (d, params) => params.monthNames[op.month(d.Date)] }) // use it to get the name
.select("Date", "month")
.view()
Insert cell
protests.view()
Insert cell
// Get the (numeric) month
numeric_month = protests
.derive({ month_num: d => op.month(d.Date) })
.select("Date", "month_num")
.view()
Insert cell
protests
.derive({ month: d => op.format_date(d.Date, { month: "long" }) })
.select("Date", "month")
.view()
Insert cell
// Try to access the month name using localDateString (errors out)
protests.derive({
month_num: d => d.Date.toLocaleDateString("default", { month: "long" })
})
Insert cell
// Tried to use a separate array, but can't seem to reference it properly
month_name = protests
.derive({ month_num: d => op.month(d.Date) })
.derive({ month_name: d => monthNames[d.month_num] })
.select("Date", "month_num")
.view()
Insert cell
Insert cell
// Couldn't figure out how to use localDateString natively in Arquero
monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
Insert cell
data = JSON.stringify([
{ date: "2020-01-01", value: 10 },
{ date: "2020-02-01", value: 11 }
])
Insert cell
import { aq, op } from "@uwdata/arquero"
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