Public
Edited
Mar 5, 2023
Insert cell
Insert cell
database = FileAttachment("f1_db.sqlite").sqlite()
Insert cell
database
SELECT res.position, res.points, ra.year, ra.name, st.status
FROM results AS res
LEFT JOIN races AS ra
on res.raceId=ra.raceID
LEFT JOIN drivers
on res.driverId=drivers.driverId
LEFt JOIN status AS st
on res.statusId=st.statusId
WHERE drivers.driverRef='max_verstappen'
Insert cell
Insert cell
df = aq.from(query)
Insert cell
df
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
viewof bars_color = Inputs.color({label: "Chart color:", value: "#000B8D"})
Insert cell
Insert cell
Plot.plot({
x: {tickFormat: "d"},
marks:[
Plot.barY(avg_points_by_year, {x:"year", y: "avgPoints", fill: bars_color}),
Plot.ruleY([0]),
Plot.linearRegressionY(avg_points_by_year, {x:"year", y:"avgPoints", opacity: 1})
]
})
Insert cell
avg_points_by_year = df
.groupby('year')
.rollup({
avgPoints: d => op.mean(d.points)
})
Insert cell
Insert cell
wins = df
.filter(d => d.position == 1)
Insert cell
wins.view()
Insert cell
winCount = wins
.groupby("year")
.count()
Insert cell
Type Markdown, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Plot.plot({
x: {tickFormat: "d"},
marks:[
Plot.barY(winCount, {x:"year", y: "count", fill: bars_color}),
Plot.textY(winCount, {x:"year", y:"count", text:"count", dy: -8, fontSize: 13}),
Plot.ruleY([0])
//Plot.linearRegressionY(wins, {x:"year", y:"avgPoints"})
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barX(query, Plot.groupY({x : "count"}, {y:"status"})),
Plot.ruleX([0])
],
marginLeft: 100
})
Insert cell
crashes = df
.filter(d => op.includes(["Accident", "Collision", "Collision damage", "Spun off"], d.status))
Insert cell
crashes.view()
Insert cell
Insert cell
counts = crashes
.groupby("year", "status")
.count()
.orderby('year', 'status')
Insert cell
counts.view()
Insert cell
Plot.plot({
x: {tickFormat: "d"},
y: {interval: 1, tickFormat: "d"},
color: {
legend:true
},
marks: [
Plot.barY(counts, {x: "year", y:"count", fill: "status"}),
Plot.ruleY([0])
]
})
Insert cell
Type Markdown, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
import { aq, op } from '@uwdata/arquero'
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