Python data loaders
Observable Framework supports data loaders written in Python by passing them to the python3 command. The latter must be available on your $PATH. Any library used by your scripts must also be installed.
CSV
The data loader below reads in the penguins data from a local file, performs logistic regression, then outputs a single CSV with the original penguin data enriched with species classifications.
Create a file in your project source root with the .csv.py double extension (for example, docs/data/my-data.csv.py), then paste the Python code below to get started.
Access the output of the data loader from the client using FileAttachment:
const penguinClassification = FileAttachment("data/penguin-logistic.csv").csv({typed: true});
The file attachment name does not include the .py extension. We rely on Framework’s routing to run the appropriate data loader.
We can now display the dataset with the predictions:
Inputs.table(penguinClassification)
PNG
The data loader below accesses birth data for Lake County, Illinois from a local geoJSON file. A simple choropleth of birth rates is created using matplotlib, and output as a PNG file.
Create a file in your project source root with the .png.py double extension (for example, docs/data/my-png.png.py), then paste the Python code below to get started.
Access the output of the data loader from the client using FileAttachment:
const birthRateMap = FileAttachment("data/birth-statistics.png").image();
The file attachment name does not include the .py extension. We rely on Framework’s routing to run the appropriate data loader.
birthRateMap
Zip
The data loader below accesses data on earthquakes from the USGS, then combines metadata (as JSON) and selected earthquake magnitude and location (as a CSV) in a zip archive.
Create a file in your project source root with the .zip.py double extension (for example, docs/data/my-data.zip.py), then paste the Python code below to get started.
Access the output of the data loader from the client using FileAttachment:
const quakeMetadata = FileAttachment("data/earthquakes/quakes_metadata.json").json()
const quakeData = FileAttachment("data/earthquakes/quakes.csv").csv({typed: true})
The file attachment name does not include the .py extension. We rely on Framework’s routing to run the appropriate data loader.
quakeData
You can alternatively access the zip archive as a whole:
const quakeZip = FileAttachment("data/earthquakes.zip").zip()
quakeZip