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
const dfd = require("danfojs-node")
let sf = new dfd.Series([1, 2, 3, 4])
let map = { 1: "ok", 2: "okie", 3: "frit", 4: "gop" }
sf.map(map).print()
Output
╔═══╤══════╗
║ 0 │ ok ║
╟───┼──────╢
║ 1 │ okie ║
╟───┼──────╢
║ 2 │ frit ║
╟───┼──────╢
║ 3 │ gop ║
╚═══╧══════╝
Mapping values in a Series to a representation using functions.
Node
Browser
const dfd = require("danfojs-node")
let sf = new dfd.Series([1,2,3,4])
sf.map((x)=>{
return `I have ${x} cat(s)`
}).print()
Output
╔ ═══╤═════════════════╗
║ 0 │ I have 1 cat(s) ║
╟───┼─────────────────╢
║ 1 │ I have 2 cat(s) ║
╟───┼─────────────────╢
║ 2 │ I have 3 cat(s) ║
╟───┼─────────────────╢
║ 3 │ I have 4 cat(s) ║
╚═══╧═════════════════╝
Last modified 1yr ago