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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more