Public
Edited
Jan 18, 2024
2 forks
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/

viewof fifa = aq // viewof shows the table view, but assigns the table value
.fromCSV(await FileAttachment("fifaData.csv").text())
.view({ height: 240 }) // set maximum height of table viewer in pixels
Insert cell
Insert cell
fifa.columnNames()
Insert cell
Insert cell
[fifa.numRows(), fifa.numCols()]
Insert cell
Insert cell
fifa.view({ limit: 5 }) // view(5) also works as a shorthand
Insert cell
Insert cell
fifa.slice(-5).view()
Insert cell
// head(data, 5)
Insert cell
// tail(data, 5)
Insert cell
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.filter(
(player) =>
player.Nationality === "Argentina" && player["Preferred Foot"] === "Left"
)
.reify() // generates a new table based on the previous operations
//.objects() // exports the table content as an array of flat objects
.numRows() // display count of rows
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.filter(
(player) =>
player.Club === "FC Barcelona" || player["Work Rate"] === "Medium/ Medium"
)
.reify()
//.objects()
.numRows()
Insert cell
Insert cell
{
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
const clubs = ["FC Barcelona", "Real Madrid"];

return (
fifa
// SOURCE for `aq.escape`: https://uwdata.github.io/arquero/api/#escape
.filter(aq.escape((player) => clubs.indexOf(player.Club) !== -1))
.reify()
//.objects()
.numRows()
);
}
Insert cell
Insert cell
{
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
// const regexp = /Argentina|Portugal/; // new RegExp('Argentina|Portugal')

return (
fifa
.filter((player) => op.match(player.Nationality, /Argentina|Portugal/))
.reify()
//.objects()
.numRows()
);
}
Insert cell
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.select("Name", "Age", "Nationality", "Club")
.reify()
//.objects()
.numRows()
Insert cell
{
const keepCols = ["Name", "Age", "Nationality", "Club"];

return (
fifa
.select(keepCols)
.reify()
//.objects()
.numRows()
);
}
Insert cell
Insert cell
fifa
.select(aq.matches(/Name|Age|Nationality/))
.reify()
//.objects()
.numRows()
Insert cell
{
const keepCols = /Name|Age|Nationality/;

return (
fifa
.select(aq.matches(keepCols))
.reify()
//.objects()
.numRows()
);
}
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
oldestPlayers = fifa
.filter((d) => d.Age > 40)
.orderby(aq.desc("Age"))
.select("Name", "Age")
.reify()
//.objects()
.view(5)
Insert cell
// SOURCE: https://uwdata.github.io/arquero/api/#names
fifa
.filter((d) => d.Age > 40)
.orderby(aq.desc("Age"))
.select("Name", "Age")
.rename(aq.names("name", "age")) // rename columns by index position
.reify()
//.objects()
.view(5)
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa.orderby("Nationality").view(8)
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa.orderby(aq.desc("Nationality")).view(4)
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa.orderby("Nationality", aq.desc("Age")).view(8) // Order by Nationality (ascending) and then by Age (descending)
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.filter(
(player) =>
op.match(player.Club, /FC Barcelona|Real Madrid/) && player.Age > 29
)
.select("Name", "Club", "Age")
.orderby("Club", aq.desc("Age"))
.rename(aq.names("name", "club", "age")) // rename columns by index position
.reify()
//.view()
//.objects()
.numRows()
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.derive({
ValueNum: aq.escape((d) => parseFloat(d.Value.slice(1, -1))),
Lefty: (d) => (d["Preferred Foot"] === "Left" ? 1 : 0)
})
.reify()
.view(10)
//.objects()
Insert cell
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.derive({
ValueNum: aq.escape((d) => parseFloat(d.Value.slice(1, -1)))
})
.groupby("Club")
.rollup({
mean_value: (d) => op.mean(d.ValueNum),
count: op.count()
})
.filter((d) => d.count > 20) // let's not trust results with little support...
.orderby(aq.desc("mean_value"))
.reify()
.view(10)
//.objects()
Insert cell
// SOURCE: https://observablehq.com/@uwdata/introducing-arquero
// SOURCE: https://uwdata.github.io/arquero/api/verbs
fifa
.derive({
ValueNum: aq.escape((d) => parseFloat(d.Value.slice(1, -1)))
})
.groupby("Nationality")
.rollup({
total_value: (d) => Math.floor(op.sum(d.ValueNum)),
avg_age: (d) => Math.round(op.mean(d.Age) * 10 ** 1) / 10 ** 1, // round function defined below with decimals=1
count: op.count()
})
.filter((d) => d.count > 20) // let's not trust results with little support...
.orderby(aq.desc("total_value"))
.reify()
.view(10)
//.objects()
Insert cell
Insert cell
Insert cell
// Create a view of the summary statistics
viewof summary_data = SummaryTable(fifa.select(aq.not(["unlabeled", "ID"])), {
label: "Fifa Soccer Players Data"
})
Insert cell
//data = FileAttachment("fifaData.csv").csv({ typed: true })
data = d3.csvParse(await FileAttachment("fifaData.csv").text(), d3.autoType)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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