Typed data from a CSV to a Tensor
Declare a schema, summarize the supplied visits fixture, inspect typed columns and materialize complete numeric features.
// The included visits.csv fixture has six synthetic records, not patient data.
// Run from the directory that contains examples/fixtures/visits.csv.
import aner.data
import aner.tensor
var schema = data.schema()
schema = data.column(schema, "record_id", "String", false)
schema = data.column(schema, "age", "Int64", true)
schema = data.column(schema, "measurement", "Float64", true)
schema = data.column(schema, "site", "String", false)
schema = data.column(schema, "eligible", "Bool", false)
let source = data.scan_csv("examples/fixtures/visits.csv", schema, missing: "NA")
let adults = data.filter(source, data.col("age") >= 18)
let selected = data.select(adults, List("measurement", "age"))
let report = data.summarize(selected, max_bytes: 1048576, batch_rows: 2)
print("Validated, selected, present and missing measurement counts")
print(data.scanned_rows(report))
print(data.rows(report))
print(data.valid(report, "measurement"))
print(data.missing(report, "measurement"))
print("Mean of present measurements")
print(data.mean(report, "measurement"))
let table = data.collect(data.filter(selected, data.col("measurement").is_present()),
max_rows: 100, max_bytes: 1048576, batch_rows: 2)
print("Collected schema")
print(data.column_name(table, 0))
print(data.column_type(table, 0))
print(data.column_nullable(table, 0))
let values = data.to_tensor(table, max_bytes: 1048576)
print("Complete numeric tensor shape and first measurement")
print(tensor.rows(values))
print(tensor.cols(values))
print(tensor.value(values, 0, 0))
Make it your experiment.
Use Aner 0.1.0 or newer. Save this program as examples/data_basics.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/data_basics.aner
aner run examples/data_basics.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires Aner 0.1.0 or newer. Requires Aner 0.0.9 or newer. Requires the native Aner 0.0.5 or newer and VS Code 0.1.48 integration. These APIs require Aner 0.0.5 or newer. Save supplied fixtures in the shown working directory paths. No external service or credentials are required for the included analysis.
visits.csv Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution