Powered By GitBook
Series.replace
Replace values given in replace param with value
danfo.Series.replace(options) [source]
Parameters
Type
Description
Default
options
Object
oldValue: The value you want to replace
newValue: The new value you want to replace the old value with
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({ oldValue: 10, newValue: -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
╚═══╧═════╝
16
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({ oldValue: 10, newValue: -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
╚═══╧═════╝
16
Copied!
Last modified 13d ago