Public
Edited
Mar 11, 2024
1 fork
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
arrow = require('apache-arrow@15.0.1')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = d3.tsv('https://cdn.jsdelivr.net/npm/world-atlas@1/world/110m.tsv')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nameField = new arrow.Field('name', new arrow.Utf8())
Insert cell
Insert cell
popEstField = new arrow.Field('pop_est', new arrow.Uint32())
Insert cell
Insert cell
continentField = new arrow.Field('continent', new arrow.Dictionary(new arrow.Utf8(), new arrow.Uint8()))
Insert cell
Insert cell
type = new arrow.Struct([nameField, popEstField, continentField])
Insert cell
Insert cell
vector = arrow.vectorFromArray(data, type)
Insert cell
Insert cell
Insert cell
builder = arrow.makeBuilder({type})
Insert cell
Insert cell
{
for (const row of data) {
builder.append(row)
}
builder.finish()
return builder.toVector()
}

Insert cell
Insert cell
table = {
const fieldNames = type.children.map((field) => field.name)
const nameVectorPairs = fieldNames.map((name, index) => [name, vector.getChildAt(index)])
const tableInput = Object.fromEntries(nameVectorPairs)
return arrow.makeTable(tableInput)
}
Insert cell
Insert cell
Insert cell
arrow.tableToIPC(table)
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