Powered By GitBook
Series.sort_values
Sorts a Series in ascending or descending order
danfo.Series.sort_values(options) [source]
Parameters
Type
Description
Default
options
Object
inplace: Boolean indicating whether to perform the operation in-place or not. Defaults to false
ascending: Whether to return sorted values in ascending order or not. Defaults to true
{ ascending: true,
inplace: false
}
Return: Series

Sort values in a Series

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
4
let sf1 = new dfd.Series(data1)
5
let sf2 = sf1.sort_values()
6
7
sf2.print()
Copied!
Output
1
╔═══╤════╗
2
║ 7 │ 0 ║
3
╟───┼────╢
4
║ 2 │ 1 ║
5
╟───┼────╢
6
║ 3 │ 2 ║
7
╟───┼────╢
8
║ 8 │ 4 ║
9
╟───┼────╢
10
║ 4 │ 4 ║
11
╟───┼────╢
12
║ 0 │ 20 ║
13
╟───┼────╢
14
║ 1 │ 30 ║
15
╟───┼────╢
16
║ 5 │ 57 ║
17
╟───┼────╢
18
║ 6 │ 89 ║
19
╚═══╧════╝
Copied!

Sort Series in-place

Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
4
let sf1 = new dfd.Series(data1)
5
sf1.sort_values({ inplace: true })
6
7
sf1.print()
Copied!
Output
1
╔═══╤════╗
2
║ 7 │ 0 ║
3
╟───┼────╢
4
║ 2 │ 1 ║
5
╟───┼────╢
6
║ 3 │ 2 ║
7
╟───┼────╢
8
║ 8 │ 4 ║
9
╟───┼────╢
10
║ 4 │ 4 ║
11
╟───┼────╢
12
║ 0 │ 20 ║
13
╟───┼────╢
14
║ 1 │ 30 ║
15
╟───┼────╢
16
║ 5 │ 57 ║
17
╟───┼────╢
18
║ 6 │ 89 ║
19
╚═══╧════╝
20
Copied!
Sort Series values in descending order
Node
1
const dfd = require("danfojs-node")
2
3
let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
4
let sf1 = new dfd.Series(data1)
5
sf1.sort_values({ "ascending": false, "inplace": true })
6
7
sf1.print()
Copied!
Output
1
╔═══╤════╗
2
║ 6 │ 89 ║
3
╟───┼────╢
4
║ 5 │ 57 ║
5
╟───┼────╢
6
║ 1 │ 30 ║
7
╟───┼────╢
8
║ 0 │ 20 ║
9
╟───┼────╢
10
║ 4 │ 4 ║
11
╟───┼────╢
12
║ 8 │ 4 ║
13
╟───┼────╢
14
║ 3 │ 2 ║
15
╟───┼────╢
16
║ 2 │ 1 ║
17
╟───┼────╢
18
║ 7 │ 0 ║
19
╚═══╧════╝
Copied!
Last modified 24d ago