DataFrame.dropna
Remove missing values (NaNs, undefined, null) for DataFrame
danfo.DataFrame.dropna(axis, options) [source]
Parameters
Type
Description
Default
axis
Int
0 or 1. If 0, drop columns with NaNs, if 1, drop rows with NaNs
1
options
Object
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{inplace: false}
Returns:
return DataFrame

Examples

Drop rows (axis=0) with missing values

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]]
4
let cols = ["A", "B", "C"]
5
let df = new dfd.DataFrame(data, { columns: cols })
6
7
df.print()
8
9
let df_drop = df.dropna(0)
10
df_drop.print()
Copied!
1
Copied!
Output
1
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗
2
║ │ A │ B │ C ║
3
╟───┼───────────────────┼───────────────────┼───────────────────╢
4
║ 0 │ 1 │ 2 │ 3 ║
5
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
Copied!

Drop columns (axis=1) with missing values

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = [[1, 2, 3], [NaN, 5, 6], [NaN, 30, 40], [39, undefined, 78]]
4
let cols = ["A", "B", "C"]
5
let df = new dfd.DataFrame(data, { columns: cols })
6
7
df.print()
8
9
df.dropna({axis: 1, inplace: true})
10
df.print()
Copied!
1
Copied!
Output
1
╔═══╤═══════════════════╗
2
║ │ C ║
3
╟───┼───────────────────╢
4
║ 0 │ 3 ║
5
╟───┼───────────────────╢
6
║ 1 │ 6 ║
7
╟───┼───────────────────╢
8
║ 2 │ 40 ║
9
╟───┼───────────────────╢
10
║ 3 │ 78 ║
11
╚═══╧═══════════════════╝
Copied!
Last modified 17d ago