Public
Edited
Feb 5, 2023
1 fork
Insert cell
md`# Extracting Data from CSV`
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
states = FileAttachment("states.json").json()
Insert cell
states_features = topojson.feature(states, states.objects.states)
Insert cell
csv_data = d3.csvParse(await FileAttachment("iowa_counties.csv").text(),({FIPS, FEMALES, POP2010}) => [FIPS, [+FEMALES, +FEMALES/+POP2010]])
Insert cell
//this is how to take the values of a variable (column) from all variables you created from the csv file
femalepct = Array.from(csv_data.values(), d => d[1][1])
Insert cell
//this is how you map the id column to the values. We will use this for joining with topojson later.
data = Object.assign(new Map(csv_data), {title: ["Females", "Female Pct"]})
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