Published
Edited
Mar 11, 2022
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
topojson = require("topojson-client@3")
Insert cell
india = FileAttachment("india.json").json()
Insert cell
india_features = topojson.feature(india, india.objects.india)
Insert cell
csv_data = d3.csvParse(await FileAttachment("india_data.csv").text(),({shapeID, area, number_of_named_languages, main_language, main_language_share, pop_total, pop_male, pop_female, literacy_all, literacy_male, literacy_female}) => [shapeID, [+area, +number_of_named_languages, main_language, +main_language_share, +pop_total, +pop_male, +pop_female, +literacy_all, +literacy_male, +literacy_female, +pop_total/+area]])
Insert cell
//take the value of population density
pop_den = Array.from(csv_data.values(), d => d[1][10])
Insert cell
//take the value of main language
main_language = Array.from(csv_data.values(), d => d[1][2])
Insert cell
//take the value of main language share
main_language_share = Array.from(csv_data.values(), d => d[1][3])
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: ["Area", "Number of Named Languages", "Main Language", "Main Language Share", "Total Population", "Male Population", "Female Population", "Total Literacy", "Male Literacy", "Female Literacy", "Population Density"]})
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