Series.replace

Replace values given in replace param with value

danfo.Series.replace(kwargs) [source]

Parameters

Type

Description

Default

kwargs["replace"]

int | String| bool

value to be replaced

kwargs["with"]

int | String | bool

value to replace the previous value

kwargs["inplace"]

Bool

mutate the series or create the new series

false

Returns: Series

Examples

Replace a value in a series and return a new series

Node
Node
const dfd = require("danfojs-node")
let data1 = [10, 45, 56, 25, 23, 20, 10]
let sf = new dfd.Series(data1)
let sf_rep = sf.replace({ replace: 10, with: -50 })
sf_rep.print()
Output
Output
╔═══╤══════════════════════╗
║ │ 0 ║
╟───┼──────────────────────╢
║ 0 │ -50 ║
╟───┼──────────────────────╢
║ 1 │ 45 ║
╟───┼──────────────────────╢
║ 2 │ 56 ║
╟───┼──────────────────────╢
║ 3 │ 25 ║
╟───┼──────────────────────╢
║ 4 │ 23 ║
╟───┼──────────────────────╢
║ 5 │ 20 ║
╟───┼──────────────────────╢
║ 6 │ -50 ║
╚═══╧══════════════════════╝

Replace a value in a series , with out returning a new series

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