danfo.streamCSV

Streams a CSV file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.

danfo.streamCSV(filePath, callback, options)

Parameters
Type
Description

filePath

string

URL or local file path to CSV file.

callback

Function

Callback function to be called once the specifed rows are parsed into DataFrame.

options

object

Optional configuration object. Supports all Papaparse config options.

The streamCSV function streams a CSV file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.

Stream CSV file from local path

const dfd = require("danfojs-node")
const path = require("path")

const filePath = path.join(process.cwd(), "raw_data", "titanic.csv");

dfd.streamCSV(filePath, (df) => {
    if (df) {
        // Do any processing here
        df.print();
    }
});
//Showing few rows 
...

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ PassengerId       │ Survived          │ Pclass            │ Name              │ ...               │ Fare              │ Cabin             │ Embarked          ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 676        │ 687               │ 0                 │ 3                 │ Panula, Mr. Jaa…  │ ...               │ 39.6875           │                   │ S                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║            │ PassengerId       │ Survived          │ Pclass            │ Name              │ ...               │ Fare              │ Cabin             │ Embarked          ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 677        │ 688               │ 0                 │ 3                 │ Dakic, Mr. Bran…  │ ...               │ 10.1708           │                   │ S                 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

...

Stream CSV file from remote path

Last updated

Was this helpful?