Series.fillNa
Replace all NaN value with specified value
danfo.Series.fillNa(options)
Parameters
Type
Description
Default
value
Any
The value to replace all missing value with.
options
Object
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{
inplace: false
}
Examples

Fill nan value and then return new series

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [NaN, 1, 2, 33, 4, NaN, 5, 6, 7, 8]
4
let sf = new dfd.Series(data1)
5
6
let sf_rep = sf.fillNa(-999)
7
8
sf_rep.print()
Copied!
Output
1
╔═══╤══════╗
2
║ 0 │ -999 ║
3
╟───┼──────╢
4
║ 1 │ 1 ║
5
╟───┼──────╢
6
║ 2 │ 2 ║
7
╟───┼──────╢
8
║ 3 │ 33 ║
9
╟───┼──────╢
10
║ 4 │ 4 ║
11
╟───┼──────╢
12
║ 5 │ -999 ║
13
╟───┼──────╢
14
║ 6 │ 5 ║
15
╟───┼──────╢
16
║ 7 │ 6 ║
17
╟───┼──────╢
18
║ 8 │ 7 ║
19
╟───┼──────╢
20
║ 9 │ 8 ║
21
╚═══╧══════╝
Copied!

Fill nan value inplace

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [NaN, 1, 2, 33, 4, undefined, 5, 6, 7, 8]
4
let sf = new dfd.Series(data1)
5
sf.fillNa(-999, { inplace: true })
6
7
sf.print()
Copied!
Output
1
╔═══╤══════╗
2
║ 0 │ -999 ║
3
╟───┼──────╢
4
║ 1 │ 1 ║
5
╟───┼──────╢
6
║ 2 │ 2 ║
7
╟───┼──────╢
8
║ 3 │ 33 ║
9
╟───┼──────╢
10
║ 4 │ 4 ║
11
╟───┼──────╢
12
║ 5 │ -999 ║
13
╟───┼──────╢
14
║ 6 │ 5 ║
15
╟───┼──────╢
16
║ 7 │ 6 ║
17
╟───┼──────╢
18
║ 8 │ 7 ║
19
╟───┼──────╢
20
║ 9 │ 8 ║
21
╚═══╧══════╝
Copied!
Last modified 12d ago