DataFrame.dropna

Remove missing values (NaNs, undefined) for DataFrame

danfo.DataFrame.dropna(kwargs) [source]

Parameters

Type

Description

Default

kwargs

Object

{axis: 0: Apply along row/index axis

1: Apply across columns axis

inplace:If true, perform operation inplace

and return None.

}

{axis: 0,

inplace: false}

Returns:

return DataFrame

Examples

Drop rows (axis=0) with missing values

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

Drop columns (axis=1) with missing values

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