Public
Edited
Jun 15, 2023
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
df_group_either = df
.groupby("citizenship")
.rollup({
n: (d) => op.sum(d.either),
total: (d) => op.count(),
share: (d) => 100 * op.mean(d.either)
})
Insert cell
df_group_daddy = df
.groupby("citizenship")
.rollup({
n: (d) => op.sum(d.daddy),
total: (d) => op.count(),
share: (d) => 100 * op.mean(d.daddy)
})
Insert cell
df_group_mommy = df
.groupby("citizenship")
.rollup({
n: (d) => op.sum(d.mommy),
total: (d) => op.count(),
share: (d) => 100 * op.mean(d.mommy)
})
Insert cell
italy = get_people({ occupation: "Q33999", citizenship: "Q38" }).then((d) =>
d.derive({ citizenship: (d) => "Italy" })
)
Insert cell
spain = get_people({ occupation: "Q33999", citizenship: "Q29" }).then((d) =>
d.derive({ citizenship: (d) => "Spain" })
)
Insert cell
canada = get_people({ occupation: "Q33999", citizenship: "Q16" }).then((d) =>
d.derive({ citizenship: (d) => "Canada" })
)
Insert cell
switz = get_people({ occupation: "Q33999", citizenship: "Q39" }).then((d) =>
d.derive({ citizenship: (d) => "Switzerland" })
)
Insert cell
belgium = get_people({ occupation: "Q33999", citizenship: "Q31" }).then((d) =>
d.derive({ citizenship: (d) => "Belgium" })
)
Insert cell
france = get_people({ occupation: "Q33999", citizenship: "Q142" }).then((d) =>
d.derive({ citizenship: (d) => "France" })
)
Insert cell
df = france
.concat(italy)
.concat(spain)
.concat(canada)
.concat(switz)
.concat(belgium)
Insert cell
Insert cell
get_people = ({
occupation = "Q33999",
citizenship = "Q142",
birthyear = 1970
}) => {
const query = `PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?year ?father ?mother WHERE {
?item wdt:P31 wd:Q5;
wdt:P106/wdt:P279* wd:${occupation};
wdt:P27 wd:${citizenship};
wdt:P569 ?birthdate;
rdfs:label ?itemLabel FILTER(lang(?itemLabel) = "fr") .
?sitelink schema:about ?item;
schema:isPartOf / wikibase:wikiGroup "wikipedia".
FILTER(YEAR( ?birthdate ) >= ${birthyear} )
BIND(YEAR(?birthdate) AS ?year)
OPTIONAL {
?item wdt:P22 ?father.
?fatherlink schema:about ?father;
schema:isPartOf <https://fr.wikipedia.org/>.
}
OPTIONAL {
?item wdt:P25 ?mother.
?motherlink schema:about ?mother;
schema:isPartOf <https://fr.wikipedia.org/>.
}
}`;

return fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`,
{ headers: { accept: "application/sparql-results+json" } }
)
.then((response) => response.json())
.then((res) =>
aq
.from(
res.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
year: d.year.value,
father: d.father?.value,
mother: d.mother?.value
}))
)
.derive({
daddy: (d) => 1 * (d.father !== undefined),
mommy: (d) => 1 * (d.mother !== undefined),
either: (d) => (d.father !== undefined) | (d.mother !== undefined),
both: (d) => (d.father !== undefined) & (d.mother !== undefined)
})
);
}
Insert cell
Insert cell
Insert cell
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