Public
Edited
Nov 18, 2022
Insert cell
Insert cell
import { DuckDBClient } from "@cmudig/duckdb"
Insert cell
dbClient = DuckDBClient.of([FileAttachment("covid__casos.parquet")])
Insert cell
dbClient
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
nRows = dbClient.queryRow("SELECT count(*)::INT as count FROM covid__casos")
Insert cell
casos_x_provincia = dbClient.sql`
SELECT provincia, fallecido, count(*)::INT as cantidad
FROM covid__casos
WHERE provincia not like 'Ministerio %'
GROUP BY 1,2
ORDER BY 1,2`
Insert cell
casos_x_mes = dbClient.sql`
SELECT date_trunc('month', fecha) as mes, count(*)::INT as cantidad
FROM covid__casos
WHERE fallecido = 'SI'
GROUP BY 1 order by 1`
Insert cell
dbClient
select 100.0*(select 1.0*count(*) from covid__casos where fallecido = 'SI') / (select 1.0*count(*) from covid__casos)

Insert cell
dbClient
--- no entiendo, porque la sum(CASE ...) me devuelve un vector con 4 elementos
SELECT provincia,
sum(CASE WHEN fallecido = 'SI' THEN 1 ELSE 0 END) as fallecidos_count,
count(*)::int as casos_count
FROM covid__casos
group by provincia
order by fallecidos_count desc
Insert cell
Plot.plot({
marks: [
Plot.barX(casos_x_provincia, {
x: "cantidad",
y: "provincia",
sort: { y: "x", reverse: true }
}),
Plot.ruleX([0])
],
marginLeft: 120
})
Insert cell
Plot.plot({
marks: [
Plot.barX(casos_x_provincia, {
x: "cantidad",
y: "provincia",
fill: "fallecido",
sort: { y: "x", reverse: true }
}),
Plot.ruleX([0])
],
marginLeft: 100
})
Insert cell
dbClient
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
marks: [
Plot.rectY(casos_x_mes, {
x: "mes",
y: "cantidad",
interval: d3.utcMonth
}),
Plot.ruleY([0])
],
marginLeft: 100
})
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