Published
Edited
Apr 1, 2019
1 fork
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const data = [];
names.forEach(d => {
const race_data = raw_race_data.find(t => t.geoid == d);
const age_data = raw_age_data.find(t => t.geoid == d);
const income_data = raw_income_data.find(t => t.geoid == d);
const education_data = raw_education_data.find(t => t.geoid == d);
const tenure_data = raw_tenure_data.find(t => t.geoid == d);
const cdc_data = raw_cdc_data.get(d) != undefined ? raw_cdc_data.get(d) : [undefined, undefined];
data.push({
"geoid": d,
"Non-white population (%)": ((+race_data.total-race_data.white_alone)/+race_data.total)*100,
"Median household income ($)": +income_data.median,
"Bachelor's degree or higher (%)": (+education_data.total_bachelors_or_higher/+education_data.total)*100,
"Renter-occupied units (%)": (+tenure_data.renter_occupied/+tenure_data.housing_units)*100,
"Median age": +age_data.median,
"Diabetes rate": cdc_data[0]
})
})
return Object.assign(data, {columns:[
"Non-white population (%)",
"Median household income ($)",
"Bachelor's degree or higher (%)",
"Renter-occupied units (%)",
"Median age",
"Diabetes rate"
]});
}
Insert cell
names = raw_income_data.map(d => d.geoid)
Insert cell
raw_cdc_data = Object.assign(new Map(await d3.csv("https://gist.githubusercontent.com/mbostock/74a5eafd839597f6c66a1c1dcb6f499f/raw/1742edce177a3b6d059715d2e04fa1315f23c600/cdc-diabetes-obesity.csv", ({county, diabetes, obesity}) => [county, [+diabetes, +obesity]])), {title: ["Diabetes", "Obesity"]})
Insert cell
raw_tenure_data = await d3.csv("https://raw.githubusercontent.com/datadesk/census-data-downloader/714bf0e5c03572360dd750fe93c0873218351973/data/processed/acs5_2017_tenure_counties.csv")
Insert cell
raw_education_data = await d3.csv("https://raw.githubusercontent.com/datadesk/census-data-downloader/714bf0e5c03572360dd750fe93c0873218351973/data/processed/acs5_2017_education_counties.csv")
Insert cell
raw_income_data = await d3.csv("https://raw.githubusercontent.com/datadesk/census-data-downloader/714bf0e5c03572360dd750fe93c0873218351973/data/processed/acs5_2017_medianhouseholdincome_counties.csv")
Insert cell
raw_age_data = await d3.csv("https://raw.githubusercontent.com/datadesk/census-data-downloader/714bf0e5c03572360dd750fe93c0873218351973/data/processed/acs5_2017_medianage_counties.csv")
Insert cell
raw_race_data = await d3.csv("https://raw.githubusercontent.com/datadesk/census-data-downloader/07bfd86ac885f01115488e4b5b6143e0b5c7d38c/data/processed/acs5_2017_race_counties.csv")
Insert cell
keys = data.columns
Insert cell
Insert cell
Insert cell
Insert cell
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