DataFrame.count
Count non-NaN cells for each column or row. The values NaN and undefined are considered NaN
danfo.DataFrame.count(options) [source]
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 }
Returns:
return Series

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 ║
3
╟───────┼──────────────────────╢
4
║ Name │ 3 ║
5
╟───────┼──────────────────────╢
6
║ Count │ 2 ║
7
╟───────┼──────────────────────╢
8
║ Price │ 4 ║
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
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 0 │ 2 ║
5
╟───┼──────────────────────╢
6
║ 1 │ 3 ║
7
╟───┼──────────────────────╢
8
║ 2 │ 2 ║
9
╟───┼──────────────────────╢
10
║ 3 │ 2 ║
11
╚═══╧══════════════════════╝
Copied!

Last modified 17d ago