Public
Edited
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db = {
const gentoo = {
url : () => "https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.220.7&entityid=e03b43c924f226486f2f0ab6709d2381",
mimeType: 'text/csv',
name: 'gentoo'
}

const adelie = {
url : () => "https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.219.5&entityid=002f3893385f710df69eeebe893144ff",
mimeType: 'text/csv',
name: 'adelie'
}

const chinstrap = {
url : () => "https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.221.8&entityid=fe853aa8f7a59aa84cdd3197619ef462",
mimeType: 'text/csv',
name: 'chinstrap'
}
return DuckDBClient.of({
gentoo: {file: gentoo},
adelie: {file: adelie},
chinstrap: {file: chinstrap}
})

// ou cette écriture plus compacte
const myCSVFiles = {
gentoo : "https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.220.7&entityid=e03b43c924f226486f2f0ab6709d2381",
adelie: "https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.219.5&entityid=002f3893385f710df69eeebe893144ff",
chinstrap: "https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.221.8&entityid=fe853aa8f7a59aa84cdd3197619ef462"
}

const myCSVFilesForDuckDB = Object.entries(myCSVFiles).map(d => ({ url: () => d[1], mimeType: 'text/csv', name: d[0] }))
.map(d => [d.name, {file : d}])
return DuckDBClient.of(
Object.fromEntries(myCSVFilesForDuckDB)
)
}
Insert cell
db.query('SHOW TABLES')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db
WITH penguinsCombo AS (
SELECT * FROM gentoo
UNION SELECT * FROM adelie
UNION SELECT * FROM chinstrap
)
--SELECT * replace (REGEXP_EXTRACT(Species, '\w+') as Species) from penguinsCombo
SELECT island, str_split(Species, ' ')[1] as species,
CASE WHEN sex is null OR sex = '.' THEN NULL ELSE lcase(sex) END AS sex,
"Culmen Length (mm)" AS bill_length_mm, "Culmen Depth (mm)" AS bill_depth_mm,
"Body Mass (g)" AS body_mass_g, "Flipper Length (mm)" AS flipper_length_mm
FROM penguinsCombo
WHERE bill_length_mm IS NOT null
Insert cell
Insert cell
Insert cell
penguins
SELECT species, AVG(bill_length_mm / bill_depth_mm) AS bill_ratio
FROM penguins
WHERE sex = 'female'
GROUP BY ALL
ORDER BY 1
Insert cell
Insert cell
Insert cell
Insert cell
penguins
X
bill_length_mm
Y
bill_depth_mm
Color
species
Size
body_mass_g
Facet X
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Plot.plot({
color: { legend: true },
marks: [
Plot.dot(penguins, {
x: "bill_length_mm",
y: "bill_depth_mm",
fill: "species",
tip: true,
r: "body_mass_g",
opacity: 0.5
}),
Plot.frame()
],
color: {range: ["teal", "darkorange", "orchid"]},
r: {domain: d3.extent(penguins.map(d => d.body_mass_g)), range: [1, 20]},
grid: true
})
Insert cell
Insert cell
Insert cell
import {PlotMatrix} with {data} from "@observablehq/autoplot-matrix"
Insert cell
Insert cell
data = penguins
Insert cell
PlotMatrix(data)
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.rectY(
penguins,
Plot.binX(
{ y: "count" },
{ x: (d) => d[chooseVar], fill: "species", fy: "species"}
)
),
Plot.frame()
],
marginRight: 100
})
Insert cell
penguins
X
body_mass_g
Y
Color
Size
Facet X
sex
Facet Y
species
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
viewof chooseWidth = Inputs.range([50, 500], {label: "Bin width:", step: 10})
Insert cell
Plot.plot({
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
penguins,
Plot.binX(
{ y: "count" },
{ fx: "sex", fy: "species", x: "body_mass_g", tip: true, fill: "species", interval: chooseWidth }
)
),
Plot.ruleY([0])
],
marginRight: 100,
width: 800
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {scale} from "@chrispahm/hierarchical-clustering"
Insert cell
penguins
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
penguinsComplete = penguins.filter((d) => d.bill_length_mm !== null)// && d.sex == "female")
Insert cell
penguinsScale = scale(penguinsComplete)
Insert cell
penguinsArray = penguinsScale.map(
(d) => [d.bill_length_mm, d.bill_depth_mm, d.body_mass_g, d.flipper_length_mm]
)
Insert cell
Insert cell
Insert cell
penguinsClusters = ML.KMeans(penguinsArray, 3)
Insert cell
clusters = penguinsClusters.clusters.map(d => ({clusterNo: d}))
Insert cell
Insert cell
db2 = DuckDBClient.of({penguinsComplete, clusters})
Insert cell
db2
select * from penguinsComplete POSITIONAL JOIN clusters
Insert cell
Insert cell
myChart = Plot.plot({ // Remember to name if you want to use embeds!
marks: [
Plot.text(penguinsKmeans, {
x: "body_mass_g",
y: "flipper_length_mm",
text: "clusterNo",
fontSize: "15px",
fontWeight: 500,
fill: "species",
tip: true
})
],
color: { legend: true }
})
Insert cell
penguinsKmeans
select species, clusterno, count(*) as eft from penguinskmeans group by all
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
penguinsKeyCopy = penguins
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