Series.sortValues

Sorts a Series in ascending or descending order

danfo.Series.sortValues(options) [source]

ParametersTypeDescriptionDefault

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

const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)
let sf2 = sf1.sortValues()

sf2.print()
╔═══╤════╗
║ 7 │ 0  ║
╟───┼────╢
║ 2 │ 1  ║
╟───┼────╢
║ 3 │ 2  ║
╟───┼────╢
║ 8 │ 4  ║
╟───┼────╢
║ 4 │ 4  ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 6 │ 89 ║
╚═══╧════╝

Sort Series inplace

const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)
sf1.sort_values({ inplace: true })

sf1.print()
╔═══╤════╗
║ 7 │ 0  ║
╟───┼────╢
║ 2 │ 1  ║
╟───┼────╢
║ 3 │ 2  ║
╟───┼────╢
║ 8 │ 4  ║
╟───┼────╢
║ 4 │ 4  ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 6 │ 89 ║
╚═══╧════╝

Sort Series values in descending order

const dfd = require("danfojs-node")

let data1 = [20, 30, 1, 2, 4, 57, 89, 0, 4]
let sf1 = new dfd.Series(data1)
sf1.sortValues({ "ascending": false, "inplace": true })

sf1.print()
╔═══╤════╗
║ 6 │ 89 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 4 │ 4  ║
╟───┼────╢
║ 8 │ 4  ║
╟───┼────╢
║ 3 │ 2  ║
╟───┼────╢
║ 2 │ 1  ║
╟───┼────╢
║ 7 │ 0  ║
╚═══╧════╝

Last updated