Public
Edited
Oct 16, 2022
2 stars
Insert cell
Insert cell
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
Insert cell
states = FileAttachment("states.csv").csv({ typed: true })
Insert cell
Insert cell
states_table = aq.from(states)
Insert cell
Insert cell
Inputs.table(states_table)
Insert cell
states_table.view()
Insert cell
Insert cell
viewof selected_region1 = Inputs.select(states.map(d => d.Region), {sort: true, unique: true, label: "Select region:"})
Insert cell
Insert cell
viewof selected_region = Inputs.select(states_table
.select('Region')
.dedupe()
.filter((d) => !!d.Region) // conventional JavaScript way to filter for "value is not NULL."
.orderby('Region')
.array('Region')
)
Insert cell
Insert cell
viewof selected_region2 = Inputs.select(op.compact(
states_table
.select('Region')
.dedupe()
.orderby('Region')
.array('Region')
)
)
Insert cell
Insert cell
viewof min_change = Inputs.range([min_val, max_val], {label: "Minimum 2020 Pct Pop Change", step: 1, value: min_val})
Insert cell
min_val = Math.round(Math.min(...states_table.array('PctChange_2020')))

Insert cell
max_val = Math.round(Math.max(...states_table.array('PctChange_2020')))
Insert cell
Insert cell
filtered_states_table = states_table
.params({ selected_region, min_change })
.filter((d) =>
d.Region == selected_region && d.PctChange_2020 >= min_change
).view()
Insert cell
Insert cell
filtered_states_table_alternate = states_table
.params({
reg: selected_region,
min: min_change
})
.filter((d, $) => op.includes($.reg, d.Region) && d.PctChange_2020 >= $.min )
.view()
Insert cell
Insert cell
Mean and Median Population by Division for the ${selected_region} Region
Insert cell
filtered_states_table_rollup = states_table
.params({
reg: selected_region,
min: min_change
})
.filter((d, $) => op.includes($.reg, d.Region) && d.PctChange_2020 >= $.min )
.groupby('Division')
.rollup({
MeanPop_2020: d => op.round(op.mean(d.Pop_2020)),
MeadianPop_2020: d => op.median(d.Pop_2020)
})
.view()





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