Public
Edited
Oct 10, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
query = `SELECT ?laureateLabel ?awardLabel ?countryLabel ?year ?sitelinks WHERE {
?award (wdt:P279+) wd:Q7191.
?laureate p:P166 ?statement.
?statement ps:P166 ?award;
pq:P585 ?date.
BIND(YEAR(?date) AS ?year)
?laureate wdt:P27 ?country ;
wikibase:sitelinks ?sitelinks;
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY (?year) (?awardLabel)`
Insert cell
data = fetch(
`https://query-main.wikidata.org/sparql?query=${encodeURIComponent(query)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((d) => d.json())
Insert cell
df = aq.from(
data.results.bindings.map((d) => ({
laureate: d.laureateLabel.value,
country: d.countryLabel.value,
award: d.awardLabel.value,
year: parseInt(d.year.value)
}))
)
Insert cell
countries = df
.groupby(["award", "country"])
.count()
.groupby("award")
.orderby("award", aq.desc("count"))
.derive({
share: (d) => d.count / op.sum(d.count),
rank: (d) => op.rank()
})
Insert cell
Inputs.table(countries, { layout: "auto", select: false })
Insert cell
aggregate = countries
.rollup({
share_lead: (d) => op.max(d.count) / op.sum(d.count),

herfindahl: (d) => op.sum(d.share ** 2)
})
.orderby(aq.desc("share_lead"))
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