Public
Edited
Apr 3, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
median_age_by_countries = {
let data;

data = [];
list_of_countries_by_median_age_un.map((d) => {
let {
"Region, subregion, country or area": longName,
Type,
subRegion,
SDGRegion
} = d;
years.map((year) => {
data.push(
Object.assign(
{ longName, Type, subRegion, SDGRegion },
{ year: parseInt(year), medianAge: d[year] }
)
);
});
});

return data;
}
Insert cell
median_age_by_countries
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
years = {
let data = [];
for (const value in list_of_countries_by_median_age_un[0]) {
if (value.startsWith("20") || value.startsWith("19")) data.push(value);
}
return data;
}
Insert cell
data = different_cia_un_estimation.joint
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
different_cia_un_estimation = {
let cia, un, countries, joint;

cia = list_of_countries_by_median_age_cia_raw.map((d) =>
Object.assign(
{},
{
country: d["Country/Territory"],
median2020: d["2020 medians Combined"],
femaleMoreThanMale: d["2020 medians Difference (female minus male)"]
}
)
);

cia.map((d) => {
if (d["country"] === "United States") {
d["country"] = "United States of America";
}
});

un = list_of_countries_by_median_age_un_raw.map((d) =>
Object.assign(
{},
{
country: d["Region, subregion, country or area"],
median2020: d["2020"],
subRegion: d["subRegion"]
}
)
);

countries = un.map((d) => d.country);
countries = cia
.filter((d) => countries.indexOf(d.country) !== -1)
.map((d) => d.country);

let unFound, ciaFound;
joint = countries.map((country) => {
ciaFound = cia.find((d) => d.country === country);
unFound = un.find((d) => d.country === country);
return Object.assign(
{ country },
{
ciaMedian2020: ciaFound.median2020,
femaleMoreThanMale: ciaFound.femaleMoreThanMale,
unMedian2020: unFound.median2020,
subRegion: unFound.subRegion
}
);
});

return { cia, un, countries, joint };
}
Insert cell
Insert cell
list_of_countries_by_median_age_cia = list_of_countries_by_median_age_cia_raw
Insert cell
list_of_countries_by_median_age_cia
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
list_of_countries_by_median_age_un = {
let data, SDGRegion, subRegion;

list_of_countries_by_median_age_un_raw;

SDGRegion = "WORLD";
subRegion = "World";
data = list_of_countries_by_median_age_un_raw.map((d, i) => {
if (d["Type"] === "SDG region")
SDGRegion = d["Region, subregion, country or area"];

if (d["Type"] === "Subregion")
subRegion = d["Region, subregion, country or area"];

return Object.assign(d, { i, subRegion, SDGRegion });
});

return data;
}
Insert cell
list_of_countries_by_median_age_un
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
List_of_countries_by_median_age_cia@1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
List_of_countries_by_median_age_un.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
d3 = require("d3")
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