Data-Forge

JavaScript data wrangling, transformation and analysis toolkit

Want to learn JavaScript data wrangling and analysis? Then buy the book on it.

Do your prototyping and exploratory data analysis in JavaScript with Data-Forge Notebook

DataForge TypeScript is here! Show support by adding a star to the repo.

Install

Node.js:

npm install --save data-forge

Browser:

bower install --save data-forge

Download from Github

Import

var dataForge = require('data-forge');

Transform CSV data files

dataForge.readFileSync('input.csv')     // Read input file.
    .parseCSV()                         // Parse CSV data to a dataframe. 
    .parseInts("Column2", "Column3")    // Parse from strings to integers.
    .parseDates("Column4")              // Parse from strings to date objects.
    .dropSeries("Column5")              // Don't want column 5.
    .where(row => predicate(row))       // Filter out rows that you don't want.
    .select(row => transform(row))      // Apply transformation to each row.
    .asCSV()                            // Write out data file in CSV (or other) format.
    .writeFileSync('output.csv');       // Write output file.

Transform JSON data files

dataForge.readFileSync('input.json')         // Read input file.
        .parseJSON()                         // Parse JSON data to a dataframe. 
        .parseDates("Column4")               // Parse from strings to date objects.
        .dropSeries("Column5")               // Don't want column 5.
        .where(row => predicate(row))        // Filter out rows that you don't want.
        .select(row => transform(row))       // Apply transformation to each row.
        .asJSON()                            // Write out data file in CSV (or other) format.
        .writeFileSync('output.json');       // Write output file.

Transform any old JavaScript data!!

const inputData = [ /* a JavaScript array of data records */ ];
const transformedData = new dataForge.DataFrame(inputData)
        .dropSeries("Column5")               // Don't want column 5.
        .where(row => predicate(row))        // Filter out rows that you don't want.
        .select(row => transform(row))       // Apply transformation to each row.
        .toArray()                           // Back to normal JavaScript data!.

Sort, aggregate and analyse your data

var salesData = dataForge.readFileSync('sales.csv')
    .asCSV()
    .parseDates("Date")
    .parseFloats("Sales");

var summmarized = salesData
    .orderBy(row => row.Date)                               // Sort by date.
    .groupBy(row => row.ClientName)                         // Group by client.
    .select(group => ({                                     // Aggregate sales per client.
        ClientName: group.first().ClientName,
        Average: group.select(row => row.Sales).average(),  // Average sales per client.
        Total: group.select(row => row.Sales).sum(),        // Sum sales per client.
    }))
    .inflate();                                             // Series -> dataframe.

salesData.asCSV().writeFileSync('sales-by-client.csv');

And much more...

You can support Data-Forge by buying Data Wrangling with JavaScript.