Public
Edited
Dec 6, 2023
1 star
Insert cell
# First notebook:Testing Wikidata and Sparql
Insert cell
Insert cell
Insert cell
import {tex} from "@lukesmurray/wikidata-sparql-cell-mode-hack"
Insert cell
Insert cell
Insert cell
query_nyt_obi_by_year = `
SELECT ?year (COUNT(?q) AS ?count) WHERE {
SELECT DISTINCT ?q (YEAR(?date) AS ?year) (MONTH(?date) AS ?month) WHERE {
?q wdt:P31 wd:Q309481 ; wdt:P1433 wd:Q9684 .
?q wdt:P577 ?date.
FILTER(?date >= "2011-01-01"^^xsd:dateTime && ?date < "2023-01-01"^^xsd:dateTime) .
}
}
GROUP BY ?year
ORDER BY ?year
`
Insert cell
res_nyt_obi_by_year = fetch(`https://query.wikidata.org/sparql?query=${encodeURIComponent(query_nyt_obi_by_year)}`, {headers: {accept: "application/sparql-results+json"}}).then(response => response.json())
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
df_nyt_obi_by_year = aq.from(res_nyt_obi_by_year.results.bindings.map(res => ({
year: res.year.value,
count: res.count.value
})))
Insert cell
df_nyt_obi_by_year.view()
Insert cell
import {vl} from "@vega/vega-lite-api-v5"
Insert cell
vl.markBar().data(
df_nyt_obi_by_year
).encode(
vl.y().field("count").type('quantitative').title("Number of obituaries"),
vl.x().field("year").type('ordinal').title("Year"),
vl.tooltip(['year', 'count'])
).width(width) // full width
.render()
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