DataFrame.count
Count non-NaN cells for each column or row. The values NaN and undefined are considered NaN
danfo.DataFrame.count(options)
Parameters
Type
Description
Default
options
Object
axis: 0 or 1. If 0, compute the mean column-wise, if 1, row-wise. Defaults to 1
{ axis: 1 }

Examples

Count Non-NaN values along default axis 1 (column)

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = { "Name": ["Apples", "Mango", "Banana", undefined],
4
"Count": [NaN, 5, NaN, 10],
5
"Price": [200, 300, 40, 250] }
6
7
let df = new dfd.DataFrame(data)
8
df.count().print()
Copied!
1
Copied!
Output
1
╔═══╤═══╗
2
║ 0 │ 2 ║
3
╟───┼───╢
4
║ 1 │ 3 ║
5
╟───┼───╢
6
║ 2 │ 2 ║
7
╟───┼───╢
8
║ 3 │ 2 ║
9
╚═══╧═══╝
Copied!

Count Non-NaN values along row axis (0)

Node
Browser
1
const dfd = require("danfojs-node")
2
3
let data = { "Name": ["Apples", "Mango", "Banana", undefined],
4
"Count": [NaN, 5, NaN, 10],
5
"Price": [200, 300, 40, 250] }
6
7
let df = new dfd.DataFrame(data)
8
df.count({axis: 0}).print()
Copied!
1
Copied!
Output
1
╔═══════╤═══╗
2
║ Name │ 3 ║
3
╟───────┼───╢
4
║ Count │ 2 ║
5
╟───────┼───╢
6
║ Price │ 4 ║
7
╚═══════╧═══╝
Copied!