Import and Transform Data

This page covers operations for importing data, defining transforms, and deriving new tables in Mascot.

async msc.csv(url)

Imports a CSV file as a DataTable.

  • url (String): path to the file
  • Return type: Promise

async msc.csvFromString(data, name)

Imports CSV text as a DataTable.

  • data (String): CSV text
  • name (String): table name
  • Return type: Promise

async msc.treeJSON(url)

Imports tree data in JSON format as a Tree.

  • url (String): path to the file
  • Return type: Promise

async msc.graphJSON(url)

Imports graph data in JSON format as a Network.

  • url (String): path to the file
  • Return type: Promise

msc.transform(type, params)

Defines a predefined transform spec for use with scene.derive(...).

  • type (String): predefined transform type such as "bin", "filter", or "kde"
  • params (Object): configuration object for the transform type
  • Return type: Object

msc.transform(“custom”, fn, params)

Defines a custom transform spec for use with scene.derive(...).

  • fn (Function): (inTbl, outTbl, spec) => void
  • params (Object, optional): initial mutable state for the custom transform
  • Return type: Object

scene.derive(table, transformSpec)

Applies a transform spec to a source DataTable and returns a new derived table.

  • table (DataTable): source table
  • transformSpec (Object): object returned by msc.transform(...)
  • Return type: DataTable

Example: interval filter

let scene = msc.scene();
let dt = await msc.csv("/datasets/csv/gapminder.csv");
let years = dt.unique("year").sort((a, b) => a - b);
let yearFilter = msc.transform("filter", {
    attribute: "year",
    type: "interval",
    value: [years[0], years[0]]
});
let yearData = scene.derive(dt, yearFilter);

Example: dynamic binning

let scene = msc.scene();
let dt = await msc.csv("/datasets/csv/car-weight.csv");
let binSpec = msc.transform("bin", { attribute: "weight(lbs)", numBins: 8 });
let binned = scene.derive(dt, binSpec);

For transform types and options, see Transformations.