Series.map
Map the value of a series to a function or Object
danfo.series.map(callable)
Parameter
Type
Description
Default
callable
Function or Object
A function or object({})
options
Object
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{
inplace: false
}
Example
Mapping the element in a Series words in an Object
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let sf = new dfd.Series([1, 2, 3, 4])
4
let map = { 1: "ok", 2: "okie", 3: "frit", 4: "gop" }
5
sf.map(map).print()
Copied!
1
Copied!
Output
1
╔═══╤══════╗
2
║ 0 │ ok ║
3
╟───┼──────╢
4
║ 1 │ okie ║
5
╟───┼──────╢
6
║ 2 │ frit ║
7
╟───┼──────╢
8
║ 3 │ gop ║
9
╚═══╧══════╝
Copied!
Mapping values in a Series to a representation using functions.
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let sf = new dfd.Series([1,2,3,4])
4
5
sf.map((x)=>{
6
return `I have ${x} cat(s)`
7
}).print()
Copied!
1
Copied!
Output
1
╔═══╤═════════════════╗
2
║ 0 │ I have 1 cat(s) ║
3
╟───┼─────────────────╢
4
║ 1 │ I have 2 cat(s) ║
5
╟───┼─────────────────╢
6
║ 2 │ I have 3 cat(s) ║
7
╟───┼─────────────────╢
8
║ 3 │ I have 4 cat(s) ║
9
╚═══╧═════════════════╝
Copied!
Copy link