Powered By GitBook
Series.iloc
danfo.Series.iloc() [source]
Parameters
Type
Description
Default
rows
Array, String
Array, string slice, index of row positions boolean mask to filter by.
Returns:
return Series

Examples

.iloc() is primarily integer position based (from 0 to length-1 of the axis).
Allowed inputs are:
    An integer, e.g. 5.
    A list or array of integers, e.g. [4, 3, 0].
    A boolean mask. E.g [ true, false, false ]
    A string slice object with ints, e.g. "1:7"
Note: only the start label is included, and the end label is ignored.
.iloc will raiseIndexError if a requested indexer is out-of-bounds.

Indexing specific rows by index

Node
Browser
1
const dfd = require("danfojs-node")
2
3
4
let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
5
s.iloc([0,5]).print()
6
Copied!
1
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 0 │ 12 ║
5
╟───┼──────────────────────╢
6
║ 5 │ 30 ║
7
╚═══╧══════════════════════╝
Copied!

Index by a slice of row

The iloc function also accepts string slices of the form [start: end], e.g "[0: 5]". This will return all values from index positions 0 to 4.
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
4
s.iloc(["0:5"]).print()
Copied!
1
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 0 │ 12 ║
5
╟───┼──────────────────────╢
6
║ 1 │ 34 ║
7
╟───┼──────────────────────╢
8
║ 2 │ 2.2 ║
9
╟───┼──────────────────────╢
10
║ 3 │ 2 ║
11
╟───┼──────────────────────╢
12
║ 4 │ 30 ║
13
╚═══╧══════════════════════╝
Copied!
By specifying a start index in a slice, all values after that index are returned.
Node
Browser
1
const dfd = require("danfojs-node")
2
3
let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
4
s.iloc(["5:"]).print()
Copied!
1
Copied!
Output
1
╔═══╤══════════════════════╗
2
║ │ 0 ║
3
╟───┼──────────────────────╢
4
║ 5 │ 30 ║
5
╟───┼──────────────────────╢
6
║ 6 │ 2.1 ║
7
╟───┼──────────────────────╢
8
║ 7 │ 7 ║
9
╚═══╧══════════════════════╝
Copied!

Slice Series by boolean condition

Node
1
const dfd = require("danfojs-node")
2
3
4
let s = new dfd.Series([12, 34, 2.2, 2, 30, 30, 2.1, 7])
5
s.iloc(s.gt(20)).print()
Copied!
1
╔═══╤════╗
2
║ 1 │ 34 ║
3
╟───┼────╢
4
║ 4 │ 30 ║
5
╟───┼────╢
6
║ 5 │ 30 ║
7
╚═══╧════╝
Copied!
Last modified 24d ago