Series.replace
Replace values given in replace param with value
danfo.Series.replace(oldValue, newValue, options)
Parameters
Type
Description
Default
oldValue
Any
The value you want to replace.
newValue
Any
The new value you want to replace with.
options
Object
inplace: Boolean, indicating whether to perform the operation inplace or not.
{
inplace: false
}
Returns: Series
Examples

Replace a value in a series and return a new series

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [10, 45, 56, 25, 23, 20, 10]
4
let sf = new dfd.Series(data1)
5
let sf_rep = sf.replace(10, -50)
6
7
sf_rep.print()
Copied!
Output
1
╔═══╤═════╗
2
║ 0 │ -50 ║
3
╟───┼─────╢
4
║ 1 │ 45 ║
5
╟───┼─────╢
6
║ 2 │ 56 ║
7
╟───┼─────╢
8
║ 3 │ 25 ║
9
╟───┼─────╢
10
║ 4 │ 23 ║
11
╟───┼─────╢
12
║ 5 │ 20 ║
13
╟───┼─────╢
14
║ 6 │ -50 ║
15
╚═══╧═════╝
Copied!

Replace a value in-place

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [10, 45, 56, 25, 23, 20, 10]
4
let sf = new dfd.Series(data1)
5
sf.replace(10, -50, { inplace: true})
6
7
sf.print()
Copied!
1
╔═══╤═════╗
2
║ 0 │ -50 ║
3
╟───┼─────╢
4
║ 1 │ 45 ║
5
╟───┼─────╢
6
║ 2 │ 56 ║
7
╟───┼─────╢
8
║ 3 │ 25 ║
9
╟───┼─────╢
10
║ 4 │ 23 ║
11
╟───┼─────╢
12
║ 5 │ 20 ║
13
╟───┼─────╢
14
║ 6 │ -50 ║
15
╚═══╧═════╝
Copied!