Published
Edited
Sep 12, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataSample = FileAttachment("diamonds@2.csv").csv()
Insert cell
Insert cell
data = FileAttachment("diamonds@2.csv").csv({typed: true})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
data3 = d3.json(url)
Insert cell
data4 = d3.csv(url2)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
firstFive = data.slice(0,5)
Insert cell
Insert cell
lastFive = data.slice(data.length-5, data.length)
Insert cell
Insert cell
Insert cell
data2 = firstFive.map(function(d,i){ //Here 'd' represents each row entry of firstFive dataset
return{
"": d[""],
carat: d.carat,
cut: d.cut,
color: d.color,
clarity: d.clarity,
depth: d.depth,
table: d.table,
price: d.price,
x: d.x,
y: d.y,
z: d.z
}
})
Insert cell
Insert cell
Insert cell
Insert cell
copyData = JSON.parse(JSON.stringify(firstFive))
Insert cell
Insert cell
printTable(firstFive)
// Or, can directly do: printTable(data.slice(0, 5))
Insert cell
Insert cell
import {printTable} from '@uwdata/data-utilities'
Insert cell
Insert cell
md`>Number of rows = ${data.length}<br>
Number of columns = ${Object.keys(data[0]).length}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
printTable(data.slice(0,6), [{field: 'cut', title: 'cut'}, {field: 'color', title: 'color'}, {field: 'clarity', title: 'clarity'}])
Insert cell
Insert cell
printTable(data.filter(d => d.cut === 'Ideal').slice(0,5)) //It means it takes (d) as an argument and returns (d.cut === 'Ideal')
Insert cell
Insert cell
// printTable(data.filter(function(d) {return d.cut === 'Ideal'}).slice(0,5))
Insert cell
Insert cell
{
for (const i in copyData){
copyData[i].price_per_carat = parseFloat(copyData[i].price/copyData[i].carat).toFixed(2);
}
}
Insert cell
printTable(copyData)
Insert cell
Insert cell
Insert cell
printTable(data.slice(0,6).sort((a,b) => (a.carat-b.carat))) //OR, printTable(data.slice(0, 6).sort(function(a,b) {return a.carat-b.carat}))
Insert cell
Insert cell
order = ["Ideal", "Good", "Very Good", "Premium"]
Insert cell
printTable(
data.slice(0,6).sort((a,b) => {
return (
order.indexOf(a.cut) - order.indexOf(b.cut)
);
})
)
Insert cell
Insert cell
Insert cell
keys = Object.keys(data[0])
Insert cell
Insert cell
test = fromColumns(
{
day: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
state: ['reading', 'playing', 'writing', 'interview', 'chilling']
}
)
Insert cell
import {fromColumns} from '@uwdata/data-utilities'
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
Insert cell
Insert cell
vegalite = require("vega-embed@6")
Insert cell
Insert cell
Insert cell
import {tb} from "@mariodelgadosr/target-blank"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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