Published
Edited
Jun 14, 2021
Importers
2 stars
Alien files in the National Archives
Wide and long data.
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d = table.sample(1)
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
function repr(row) {
let output = ""
output += `<a href=https://catalog.archives.gov/id/${row.naid} target="_blank"><strong>${row.name}</strong></a>, born ${row['birth date'].toString().slice(4, 15)}. Arrived from ${row.country ? row.country : "unknown country"} ${row['date of entry'] ? row['date of entry'] .toString().slice(4, 15) + "." : "."} ${row['port of entry'] ? "Port of entry " + row['port of entry'] + ". " : ""}`
if (row['naturalization date']) {
output += `Naturalization date ${new Date(row['date of entry']).toString().slice(4, 15)}`
}
if (row['sex']) {output += `Sex: ${row.sex}.`}
if (row['alias']) {output += `Alias: ${row.alias}.`}
return output
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`# Ports of entry



`
Insert cell
top_entries = table.filter(d => d["port of entry"] != "")
.derive({"port of entry": d => op.lower(d["port of entry"])})
.derive({"port of entry": d => op.replace(d["port of entry"], " (bridge)", "")})
.derive({"port of entry": d => op.replace(d["port of entry"], " (nd)", "")})
.derive({"port of entry": d => op.replace(d["port of entry"], " (ma)", "")})
.derive({"port of entry": d => op.replace(d["port of entry"], " colorado", " co")})
.derive({"port of entry": d => op.replace(d["port of entry"], " new mexico", " nm")})
.derive({"port of entry": d => op.replace(d["port of entry"], " montana", " mt")})
.derive({"port of entry": d => op.replace(d["port of entry"], " texas", " tx")})
.derive({"port of entry": d => op.replace(d["port of entry"], " pennsylvania", " pa")})
.derive({"port of entry": d => op.replace(d["port of entry"], " washington", " wa")})
.derive({"port of entry": d => op.replace(d["port of entry"], " virginia", " va")})
.derive({"port of entry": d => op.replace(d["port of entry"], " connecticut", " ct")})
.derive({"port of entry": d => op.replace(d["port of entry"], " arizona", " az")})
.derive({"port of entry": d => op.replace(d["port of entry"], " montana", " mt")})
.derive({"port of entry": d => op.replace(d["port of entry"], " michigan", " mi")})
.derive({"port of entry": d => op.replace(d["port of entry"], " north dakota", " nd")})
.derive({"port of entry": d => op.replace(d["port of entry"], " california", " ca")})
.derive({"port of entry": d => op.replace(d["port of entry"], " (ia)", "")})
.derive({"port of entry": d => op.replace(d["port of entry"], " florida", " fl")})
.derive({"port of entry": d => op.replace(d["port of entry"], " rhode island", " ri")})
.derive({"port of entry": d => op.replace(d["port of entry"], " ohio", " ri")})
.derive({"port of entry": d => op.replace(d["port of entry"], " maine", " me")})
.derive({"port of entry": d => op.replace(d["port of entry"], ", new york", ", ny")})
.derive({"port of entry": d => op.replace(d["port of entry"], " poe", "")})
.groupby("port of entry").count().orderby(aq.desc("count"))
.slice(0, 30)
Insert cell
table.filter(d => d["port of entry"] != "")
.derive({"port of entry": d => op.lower(d["port of entry"])})
.join(top_entries)
.groupby(["country", "port of entry"])
.count()
.view()
Insert cell
String.prototype.to
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`## General summary stats

These are used for--eg--the country selectors.
`
Insert cell
table.groupby("country").select("birth date", "country")
Insert cell
country_counts = {
const counts = table.groupby("country").count().orderby(aq.desc("count")).objects()
return counts.map(d => {
return {
value: d.country,
label: `${d.country} (${d.count})`,
count: d.count
}}
)
}
Insert cell
viewof overall_yearly_totals = table
.params({date_field})
.filter((d, $) => d[$.date_field] !== null)
.derive({year: (d, $) => op.year(d[$.date_field])}) // Calculate the year.
.filter(d => d.year < 2020) // Remove not available entries.
.groupby("year")
.count("year")
.derive({year: d=>d.year, overall_count: d => d.count})
.select(aq.not("count"))
.view()
Insert cell
Insert cell
Insert cell
{
// Listener to reset the sample display
country;
y_axis;
date_field;
mutable year = undefined
}
Insert cell
Insert cell
Insert cell
table = aq.fromArrow(dataset, {unpack: false})
Insert cell
dataset = fetch("https://benschmidt.org/aliens.feather").then(d => d.arrayBuffer()).then(d => arrow.Table.from(d))
Insert cell
md`## External libraries

The code below loads some libraries that allow you to load the data. No need to read down here.

`
Insert cell
embed = require.alias({
"vega": "vega@5.16.1",
"vega-lite": "vega-lite@4.16.6"
})("vega-embed@6")
Insert cell
table.filter(d => op.row_number() < 10)
Insert cell
Insert cell
arrow = require("apache-arrow@2.0")
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
d3 = require("d3@v6")
Insert cell
load_time = Date.now()
Insert cell
import { select, radio, text } from '@jashkenas/inputs'
Insert cell
import { Text } from '@observablehq/inputs'
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