locationsbyrace = toplocations
.groupby("loc1", "loc2")
.derive({
race: aq.escape((d) => (typeof d.race == "undefined" ? null : d.race))
})
.pivot("race", "count")
.rename(aq.names("loc1", "loc2", "unlisted"))
.derive({
B: aq.escape((d) => (typeof d.B == "undefined" ? null : d.B)),
F: aq.escape((d) => (typeof d.F == "undefined" ? null : d.F)),
A: aq.escape((d) => (typeof d.A == "undefined" ? null : d.A)),
U: aq.escape((d) => (typeof d.U == "undefined" ? null : d.U)),
I: aq.escape((d) => (typeof d.I == "undefined" ? null : d.I)),
W: aq.escape((d) => (typeof d.W == "undefined" ? null : d.W)),
U: aq.escape((d) => (typeof d.U == "undefined" ? null : d.U)),
unlisted: aq.escape((d) =>
typeof d.unlisted == "undefined" ? null : d.unlisted
)
})
.derive({
total: (row) => row.unlisted + row.A + row.W + row.B + row.F + row.I + row.U
})
.filter((d) => d["total"] > 10)
.derive({
pctblack: (row) =>
(100 * row.B) / (row.A + row.W + row.B + row.F + row.I + row.U)
})