Public
Edited
Feb 13
7 forks
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
stackedData = d3.stack().keys()(tableData)
// <-- Add the variable "age_buckets" here (i.e. the list of age bucket strings)
Insert cell
tableData = groupToStack(df, //attr1 , //attr2 ) // <-- Add the two relevant attributes from the dataset `df` to group by (i.e. "nationality" and "age_bucket") as strings here
.map((d, i) => ({
...d,
total: total_players_by_nationality.get(d.nationality)
}))
.sort((a, b) => b.total - a.total)
Insert cell
Insert cell
df = {
const bucketize = (val) => {
let result = "";
if (val <= 20) result = "age_lte_20";
else if (val > 20 && val <= 25) result = "age_21_25";
else if (val > 25 && val <= 30) result = "age_26_30";
else if (val > 30 && val <= 35) result = "age_31_35";
else if (val > 35 && val <= 40) result = "age_36_40";
else if (val > 40) result = "age_gt_40";
return result;
};

const mutate = (df) =>
df_imported.map((df) => ({
age_bucket: bucketize(df["age"]),
...df
}));

return mutate(df_imported);
}
Insert cell
total_players_by_nationality = d3.rollup(
df,
(v) => v.length,
(d) => d.nationality
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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