Public
Edited
Oct 16, 2024
2 forks
Importers
Insert cell
Insert cell
Insert cell
usBirths1994to2003 = FileAttachment("US_births_1994-2003_CDC_NCHS.csv").csv()
Insert cell
usBirths2000to2014 = FileAttachment("US_births_2000-2014_SSA.csv").csv()
Insert cell
Insert cell
Insert cell
forLoopVerion = {
const births = [];

for (let i = 0; i < usBirths1994to2003.length; i++) {
const birthDay = usBirths1994to2003[i];

if (parseInt(birthDay.year) < 2000) {
births.push(birthDay);
}
}

return births;
}
Insert cell
Insert cell
usBirths1994to2000 = usBirths1994to2003.filter((bd) => parseInt(bd.year) < 2000)
Insert cell
Insert cell
d3.max(usBirths1994to2000, (d) => parseInt(d.year))
Insert cell
Insert cell
births = usBirths1994to2000.concat(usBirths2000to2014)
Insert cell
Insert cell
cleanedBirths = births.map((d) => {
return {
year: parseInt(d.year),
month: parseInt(d.month),
date: parseInt(d.date_of_month),
day: parseInt(d.day_of_week),
births: parseInt(d.births),
birthday: d.month + "-" + d.date_of_month
};
})
Insert cell
Insert cell
birthData = Object.values(
cleanedBirths.reduce((acc, day) => {
//check if we have seen this day already

//if we have not ("!") seen it
if (!acc[day.birthday]) {
//create a new object for this day
acc[day.birthday] = {
month: day.month,
date: day.date,
births: 0,
count: 0
};
}
//else we have seen the day before
//so we need to add to its birth count
//also add an occurence onto the matching day for the purposes of averaging
acc[day.birthday].births += day.births;
acc[day.birthday].count++;
return acc;
}, {})
)
Insert cell
Insert cell
birthExtents = d3.extent(birthData, (d) => d.births)
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