danfo. convertFunctionTotransformer
Converts a function to a pipe transformer. Only available in Nodejs version.
danfo.convertFunctionTotransformer(func)
Parameters
Type
Description
Default
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

Node
Browser
1
const dfd = require("danfojs-node")
2
3
/*
4
* A simple function that takes each row of a DataFrame and splits the
5
* name field.
6
*/
7
const renamer = (dfRow: DataFrame) => {
8
const dfModified = dfRow["Names"].map((name) => name.split(",")[0])
9
return dfModified
10
}
11
12
const transformer = dfd.convertFunctionTotransformer(renamer)
13
console.log(transformer)
Copied!
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<!--danfojs CDN -->
8
<script src="https://cdn.jsdelivr.net/gh/opensource9ja/[email protected]/lib/bundle.js"></script>
9
<title>Document</title>
10
</head>
11
12
<body>
13
14
<script>
15
16
let data = new dfd.date_range({"start":'1/1/2018',period:5, freq:'M'})
17
console.log(data);
18
19
</script>
20
</body>
21
22
</html>
Copied!
Output
1
Transform {
2
_readableState: ReadableState {
3
objectMode: true,
4
highWaterMark: 16,
5
buffer: BufferList { head: null, tail: null, length: 0 },
6
length: 0,
7
pipes: [],
8
flowing: null,
9
ended: false,
10
endEmitted: false,
11
reading: false,
12
sync: false,
13
needReadable: false,
14
emittedReadable: false,
15
readableListening: false,
16
resumeScheduled: false,
17
errorEmitted: false,
18
emitClose: true,
19
autoDestroy: true,
20
destroyed: false,
21
errored: null,
22
closed: false,
23
closeEmitted: false,
24
defaultEncoding: 'utf8',
25
awaitDrainWriters: null,
26
writecb: null,
27
writechunk: null,
28
writeencoding: null
29
}
30
}
Copied!
Last modified 13d ago