Public
Edited
Jul 21, 2024
Insert cell
Insert cell
Insert cell
db
WITH islands AS (
SELECT UNNEST(SPLIT(${islands.join(",")}, ','))
)
SELECT * FROM penguins WHERE island IN (SELECT * FROM islands)
Insert cell
Insert cell
db = DuckDBClient.of({
penguins: penguins
})
Insert cell
db
WITH avg_mass AS (
SELECT island, AVG(body_mass_g) AS avg_body_mass
FROM penguins
WHERE body_mass_g != 'NaN'
GROUP BY island
)
SELECT p.species, p.island,
p.body_mass_g, avg_mass.avg_body_mass,
p.body_mass_g - avg_mass.avg_body_mass AS difference
FROM penguins AS p
JOIN avg_mass ON p.island = avg_mass.island
WHERE p.body_mass_g != 'NaN'

Insert cell
{
const data = _(avg_mass_hist)
.flatMap(g =>
// not copying results in: TypeError: proxy [[OwnPropertyKeys]] must return an array with only string and symbol elements
[...g.bmh].map(h => ({
species: g.species,
mass: h[0],
count: h[1],
}))
)
.value()

return Plot.plot({
marks: [
Plot.rectY(
data,
Plot.binX(
{
y: "count",
},
{
fy: "species",
x: "mass",
}
),
),
]
})
}
Insert cell
db
SELECT species, histogram(body_mass_g)::MAP(DOUBLE, INTEGER) as bmh
FROM penguins
WHERE body_mass_g != 'nan'
GROUP BY species
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