Published
Edited
Sep 9, 2021
Importers
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
compressed = compress(data, configuration, { zip: false })
Insert cell
Insert cell
jsonData = JSON.stringify(compressed)
Insert cell
Insert cell
Insert cell
decompressed = eval(compressed.decompress)(compressed)
Insert cell
Insert cell
decompressedSlice = eval(compressed.decompress)(compressed, 5, 10)
Insert cell
Insert cell
source = FileAttachment("inaturalist.csv")
Insert cell
Insert cell
data = source.csv().then((dataSet) =>
dataSet
.filter((d) => d.time_observed_at) // rows with bad dates are removed
.map((d, i) => {
// Firefox needs this to read the dates, thanks Rahul
// https://stackoverflow.com/a/21984717
const dateString = d.time_observed_at.replace(/-/g, "/");

// Dates are more efficiently encoded as numbers and the Date Object
// becomes a number automatically when encoded as "integer", "float", or "index"
d.time_observed_at = new Date(Date.parse(dateString));

// added to demonstrate an index field
d.example_index = i * 4;

// These fields are almost always matched, combining them will further reduce file size
d.species = [d.scientific_name, d.common_name].join(",");
return d;
})
)
Insert cell
Insert cell
Insert cell
Insert cell
configuration = [
{ field: "id", type: "integer", postProcess: (d) => d.toString() },
{
field: "time_observed_at",
type: "float",
precision: 6e4,
postProcess: (d) => new Date(d)
},
{ field: "quality_grade", type: "enum" },
{ field: "latitude", type: "float", precision: 6e-4 },
{ field: "longitude", type: "float", precision: 4e-4 },
{ field: "species", type: "enum" },
{ field: "example_index", type: "index" }
]
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