danfo. convertFunctionTotransformer

Converts a function to a pipe transformer. Only available in Nodejs version.

danfo.convertFunctionTotransformer(func)

ParametersTypeDescriptionDefault

func

Function

A valid JavaScript function to convert to a pipe transformer.

Returns:

return A pipe transformer that applies the function to each row of object.

The convertFunctionTotransformer takes a function and converts it to a Nodejs stream transformer function which can be used in combination with streamCsvTransformer to incrementally transform large files.

Converting a function to a transformer

const dfd = require("danfojs-node")

/*
 * A simple function that takes each row of a DataFrame and splits the
 * name field. 
*/
const renamer = (dfRow: DataFrame) => {
    const dfModified = dfRow["Names"].map((name) => name.split(",")[0])
    return dfModified
}

const transformer = dfd.convertFunctionTotransformer(renamer)
console.log(transformer)
Transform {
  _readableState: ReadableState {
    objectMode: true,
    highWaterMark: 16,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    sync: false,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    destroyed: false,
    errored: null,
    closed: false,
    closeEmitted: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    writecb: null,
    writechunk: null,
    writeencoding: null
  }
}

Last updated