Public
Edited
Nov 14, 2021
Insert cell
Insert cell
Insert cell
Insert cell
// CSV file
csvURL = "https://raw.githubusercontent.com/vega/vega-datasets/next/data/gapminder-health-income.csv"
Insert cell
// Loading it as row format
d3.csv(csvURL, d3.autoType)
Insert cell
jsonURL = "https://raw.githubusercontent.com/vega/vega-datasets/next/data/gapminder.json"
Insert cell
d3.json(
"https://raw.githubusercontent.com/vega/vega-datasets/next/data/gapminder.json"
)
Insert cell
Insert cell
Insert cell
airports = d3.csv(sheetsCSV)
Insert cell
Insert cell
dataAttached = FileAttachment("airportsfile.csv").csv()
Insert cell
Insert cell
import { data } from "@amitkaps/data-visual"
Insert cell
data
Insert cell
Insert cell
htmlCSV = "https://docs.google.com/spreadsheets/d/e/2PACX-1vRrq8hPiyMxOSYGO7bhcquEynb4nB3mKYX3ike7ALCupA05ILQnUEbdJM832EdYKrL-Lxyqq173qeI1/pub?gid=1780003412&single=true&output=csv"
Insert cell
Insert cell
d3 = require("d3")
Insert cell
aq = require("arquero")
Insert cell
popRows = d3.csv(htmlCSV)
Insert cell
popColumns = aq.loadCSV(htmlCSV)
Insert cell
Inputs.table(popRows)
Insert cell
Inputs.table(popColumns)
Insert cell
Insert cell
data
Insert cell
dataCols = aq.from(data)
Insert cell
## Core Verb for doing Transformation

- Filter
- Sort
- Derive
Insert cell
filterData = aq.from(data).filter((d) => d.Sales > 10)
Insert cell
Inputs.table(filterData)
Insert cell
// Full Form of Function
function filterSales10(data) {
return data.Sales > 10;
}
Insert cell
// Shorter way to write a function (Arrow Function)
filterSales10Short = (data) => data.Sales > 10
Insert cell
// Even shorter function (Annymous)
(data) => data.Sales > 10
Insert cell
// Make it even shorter
(d) => d.Sales > 10
Insert cell
aq.from(data).filter(filterSales10)
Insert cell
## Using a UI to Wrangle Data
Insert cell
import { Wrangler, op } from "@observablehq/data-wrangler"
Insert cell
Wrangler(data)
Insert cell
// To use copied code replace "data" with your own variable
aq
.from(data)
.filter((d) => d["Area"] === "North")
.select("Area", "Sales")
.objects() // Uncomment to return an array of objects
Insert cell
Insert cell
gapminder = d3.csv(csvURL, d3.autoType)
Insert cell
Wrangler(gapminder)
Insert cell
// To use copied code replace "data" with your own variable
// Large Countries with poplulation income
perCapitaTable = aq
.from(gapminder)
.select("country", "income", "population")
.filter((d) => d["population"] > 5000000)
.derive({ perCapitaIncome: (d) => d.income / d.population })
.orderby(aq.desc("perCapitaIncome"))
.objects() // Uncomment to return an array of objects
Insert cell
Inputs.table(perCapitaTable)
Insert cell
vl
.spec({
title: "Large Countries with High Per Capita Income",
data: { values: perCapitaTable },
mark: "bar",
encoding: {
x: { field: "country", type: "N", sort: "-y" },
y: { field: "perCapitaIncome", type: "Q" }
}
})
.render()
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