Public
Edited
Jul 24, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
// Computation of the mean, standard deviation, and z-score.
msz = {
let n = data.map((o) => o.Total);
let m = d3.mean(n);
let s = d3.deviation(n);
let q = d3.quantile(n, 0.5);
let max = d3.max(n);
return { m: m, s: s, z: (21 - m) / s, q: q, max };
}
Insert cell
Insert cell
tippy = require("tippy.js@6")
Insert cell
data = {
let data = await FileAttachment("tennis_slams@1.csv").csv({ typed: true });
data.forEach(function (d) {
if (d.Player == "Carlos Alcaraz") {
d.Total = 2;
d.Wimbledon = 1;
}
});
return data;
}
Insert cell
data.filter((o) => o.Player.slice(0, 6) == "Carlos")
Insert cell
Insert cell
viewof update_data = Inputs.button("Update data")
Insert cell
{
if (update_data == 1) {
let data = await fetch(
"https://corsproxy.io/?https://www.landoftennis.com/statistics_men/grand_slam_most_titles.htm"
)
.then((r) => r.text())
.then(function (t) {
let data = [];
d3.select(html`${t}`)
.selectAll("table")
.nodes()
.forEach(function (t) {
let rows = d3.select(t).selectAll("tr");
rows.nodes().forEach(function (r) {
let this_data = d3
.select(r)
.selectAll("td")
.nodes()
.map(function (node, i) {
let value = d3.select(node).text();
value = value == "-" ? "0" : value;
if (i == 0) {
return ["Player", value];
} else if (i == 1) {
return ["Total", value];
} else if (i == 2) {
return ["Australian Open", value];
} else if (i == 3) {
return ["French Open", value];
} else if (i == 4) {
return ["US Open", value];
} else if (i == 5) {
return ["Wimbledon", value];
}
});
if (this_data[0][1] != "Player") {
data.push(Object.fromEntries(this_data));
}
});
});

return data;
});
return data;
} else {
return md``;
}
}
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