Series.apply
Invoke a function on each value in a Series.
danfo.series.apply(callable, options)
Parameters
Type
Description
Default
callable
Function
Function (can be anonymous) to apply
options
Object
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{
inplace: false
}
Returns:
**** return Series
Example
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let sf = new dfd.Series([1, 2, 3, 4, 5, 6, 7, 8])
4
5
let apply_func = (x) => {
6
return x + x
7
}
8
sf.apply(apply_func).print()
Copied!
1
Copied!
Output
1
╔═══╤════╗
2
║ 0 │ 2 ║
3
╟───┼────╢
4
║ 1 │ 4 ║
5
╟───┼────╢
6
║ 2 │ 6 ║
7
╟───┼────╢
8
║ 3 │ 8 ║
9
╟───┼────╢
10
║ 4 │ 10 ║
11
╟───┼────╢
12
║ 5 │ 12 ║
13
╟───┼────╢
14
║ 6 │ 14 ║
15
╟───┼────╢
16
║ 7 │ 16 ║
17
╚═══╧════╝
Copied!
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let sf = new dfd.Series([1, 2, 3, 4, 5, 6, 7, 8])
4
5
sf.apply(Math.log).print()
Copied!
1
Copied!
Output
1
╔═══╤════════════════════╗
2
║ 0 │ 0 ║
3
╟───┼────────────────────╢
4
║ 1 │ 0.6931471805599453 ║
5
╟───┼────────────────────╢
6
║ 2 │ 1.0986122886681096 ║
7
╟───┼────────────────────╢
8
║ 3 │ 1.3862943611198906 ║
9
╟───┼────────────────────╢
10
║ 4 │ 1.6094379124341003 ║
11
╟───┼────────────────────╢
12
║ 5 │ 1.791759469228055 ║
13
╟───┼────────────────────╢
14
║ 6 │ 1.9459101490553132 ║
15
╟───┼────────────────────╢
16
║ 7 │ 2.0794415416798357 ║
17
╚═══╧════════════════════╝
Copied!
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let sf = new dfd.Series(["Rice","Beans","Yam","Banana","Wheat"])
4
5
sf.apply((x)=>{
6
return x.toLocaleLowerCase()
7
}).print()
Copied!
1
Copied!
Output
1
╔═══╤════════╗
2
║ 0 │ rice ║
3
╟───┼────────╢
4
║ 1 │ beans ║
5
╟───┼────────╢
6
║ 2 │ yam ║
7
╟───┼────────╢
8
║ 3 │ banana ║
9
╟───┼────────╢
10
║ 4 │ wheat ║
11
╚═══╧════════╝
Copied!
Copy link