Published
Edited
Oct 6, 2022
1 fork
Importers
1 star
Insert cell
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
usBirths1994to2000 = usBirths1994to2003
.filter((d) => parseInt(d.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
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