Public
Edited
Apr 5, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = FileAttachment("mydata@2.csv").csv({ typed: true })
Insert cell
Insert cell
Insert cell
data2 = d3.dsv(";", await FileAttachment("mydata2@2.csv").url(), d3.autoType)
Insert cell
data2
Insert cell
Insert cell
Insert cell
Workbook = FileAttachment("mydata.xlsx").xlsx()
Insert cell
Insert cell
data3 = Workbook.sheet("data", { headers: true })
Insert cell
Insert cell
Insert cell
Insert cell
zip = FileAttachment("mydata.zip").zip()
Insert cell
Insert cell
data4 = zip.file("mydata.csv").csv({ typed: true })
Insert cell
Insert cell
Insert cell
data5 = FileAttachment("mydata.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.table(data, { rows: 5 })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data.columns
Insert cell
Insert cell
data.map((d) => d.name)
Insert cell
Insert cell
data.map((d) => d["name"])
Insert cell
Insert cell
data.filter((d) => d.IDH > 0.5)
Insert cell
data.filter((d) => d.nom == "Botswana")
Insert cell
Insert cell
data.sort((a, b) => d3.ascending(a.POP, b.POP))
Insert cell
data.sort((a, b) => d3.descending(a.POP, b.POP))
Insert cell
Insert cell
Insert cell
Insert cell
newdata2 = data.map((d) => ({
id: d.iso3,
nom: d.name,
population: Math.round(d.POP * 1000) // on convertit en milliers et on arrondi
}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
op = aq.op
Insert cell
Insert cell
Insert cell
dt = aq.from(data)
Insert cell
Insert cell
Insert cell
dt.objects()
Insert cell
Insert cell
[...dt]
Insert cell
Insert cell
Insert cell
dt.columnNames()
Insert cell
dt.numCols()
Insert cell
dt.numRows()
Insert cell
Insert cell
Insert cell
html`${dt.slice(0, 5).toHTML()}`
Insert cell
Insert cell
md`${dt.slice(0, 5).toMarkdown()}`
Insert cell
Insert cell
Inputs.table(dt.objects(), { rows: 5 })
Insert cell
Insert cell
dt.array("name")
Insert cell
dt.values("name") // executez cette cellule
Insert cell
Insert cell
Insert cell
dt.get("iso3", 10)
Insert cell
Insert cell
getiso = dt.getter("iso3")
Insert cell
getiso(10)
Insert cell
Insert cell
Insert cell
dt.orderby("POP")
Insert cell
dt.orderby(aq.desc("POP"))
Insert cell
Insert cell
Insert cell
dt.dedupe("SUBREG").objects()
Insert cell
Insert cell
dt.select("name", "POP")
Insert cell
Insert cell
Insert cell
dt.slice(2, 5)
Insert cell
Insert cell
Insert cell
dt.sample(10)
Insert cell
Insert cell
Insert cell
dt.relocate("SUBREG", { after: "nom" })
Insert cell
dt.relocate("name", { before: "iso3" })
Insert cell
Insert cell
Insert cell
dt.derive({ pdppercapita: (d) => d.PIB / d.POP }, { after: "PIB" })
Insert cell
Insert cell
Insert cell
dt.rename({ name: "iso3", iso3: "id" })
Insert cell
Insert cell
dt.filter((d) => d["IDH"] > 0.5)
Insert cell
Insert cell
Insert cell
x = dt
.rollup({
min: (d) => op.min(d["POP"]),
max: (d) => op.max(d["POP"]),
mean: (d) => op.mean(d["POP"]),
median: (d) => op.median(d["POP"]),
sum: (d) => op.sum(d["POP"]),
stdev: (d) => op.stdev(d["POP"]),
count: (d) => op.count()
})
.objects()
Insert cell
Inputs.table(x)
Insert cell
Insert cell
Insert cell
dt.groupby("SUBREG").objects({ grouped: true })
Insert cell
Insert cell
summary = dt
.groupby("SUBREG")
.rollup({
min: (d) => d3.min(d["POP"]),
max: (d) => d3.max(d["POP"]),
mean: (d) => d3.mean(d["POP"]),
median: (d) => d3.median(d["POP"]),
sum: (d) => d3.sum(d["POP"]),
stdev: (d) => d3.stdev(d["POP"]),
count: (d) => d3.count()
})
.objects()
Insert cell
Inputs.table(summary)
Insert cell
Insert cell
Insert cell
Par exemple, on a **`dt1`**
Insert cell
dt1 = aq.from(data).select("iso3", "name", "POP")
Insert cell
Insert cell
Insert cell
dt2 = aq.from(data2).select("iso3", "ESPVIE", "AGEMED").rename({ iso3: "id" })
Insert cell
Insert cell
Insert cell
dt3 = dt1.join(dt2, ["iso3", "id"])
Insert cell
Insert cell
Insert cell
Insert cell
dt4 = aq
.from(data)
.select("iso3", "name", "POP", "PIB")
.orderby("POP")
.filter((d) => d["POP"] > 50)
.relocate("PIB", { before: "POP" })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mydata@2.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
mydat
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