Public
Edited
Oct 4, 2024
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
count_country = df
.filter(aq.escape((d) => d.continentLabel == c))
.groupby(["country", "countryLabel"])
.count()
.orderby(aq.desc("count"))
.derive({ share: (d) => (100 * d.count) / op.sum(d.count) })
Insert cell
query = `SELECT ?item ?itemLabel ?country ?countryLabel
WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "${wikipedia}";
wikibase:api "Generator";
mwapi:generator "links";
mwapi:titles "${article}";.
?item wikibase:apiOutputItem mwapi:item.
}
FILTER BOUND (?item)
?item wdt:P31 wd:Q5 .
?item wdt:P27 ?country .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,mul". }
}`
Insert cell
output = fetch(
`https://query-main.wikidata.org/sparql?query=${encodeURIComponent(query)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((d) => d.json())
Insert cell
entities = aq.from(
output.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
country: d.country.value,
countryLabel: d.countryLabel.value
}))
)
Insert cell
query_continent = `SELECT DISTINCT ?continent ?continentLabel ?country ?code WHERE {
VALUES ?continent {
wd:Q55643
wd:Q48
wd:Q15
wd:Q18
wd:Q49
wd:Q46
}
?continent (wdt:P527*) ?country.
?country
wdt:P2082 ?code.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,mul". }
}`
Insert cell
output_continent = fetch(
`https://query-main.wikidata.org/sparql?query=${encodeURIComponent(
query_continent
)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((d) => d.json())
Insert cell
continents = aq.from(
output_continent.results.bindings.map((d) => ({
continent: d.continent.value,
continentLabel: d.continentLabel.value,
country: d.country.value,
code: d.code.value
}))
)
Insert cell
df = entities.join_left(continents, ["country", "country"])
Insert cell
df_continent = df
.groupby(["continent", "continentLabel"])
.count()
.orderby(aq.desc("count"))
.derive({ share: (d) => (100 * d.count) / op.sum(d.count) })
Insert cell
Insert cell
Insert cell
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
wikipedia: "en.wikipedia.org",
article: "Economics"
};
if (params.has("wikipedia")) {
defaults.wikipedia = params.get("wikipedia");
}
if (params.has("article")) {
defaults.article = params.get("article");
}
return defaults;
}
Insert cell
Insert cell
import { SearchForm } from "@floatingpurr/input-autocomplete"
Insert cell
import {wikipedias} from "@pac02/user-level-gender-statistics-for-wikipedia"
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