Series.sortValues
Sorts a Series in ascending or descending order
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
Node
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()
Output
╔═══╤════╗
║ 7 │ 0 ║
╟───┼────╢
║ 2 │ 1 ║
╟───┼────╢
║ 3 │ 2 ║
╟───┼────╢
║ 8 │ 4 ║
╟───┼────╢
║ 4 │ 4 ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 6 │ 89 ║
╚═══╧════╝
Node
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()
Output
╔═══╤════╗
║ 7 │ 0 ║
╟───┼────╢
║ 2 │ 1 ║
╟───┼────╢
║ 3 │ 2 ║
╟───┼────╢
║ 8 │ 4 ║
╟───┼────╢
║ 4 │ 4 ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 6 │ 89 ║
╚═══╧════╝
Sort Series values in descending order
Node
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()
Output
╔═══╤════╗
║ 6 │ 89 ║
╟───┼────╢
║ 5 │ 57 ║
╟───┼────╢
║ 1 │ 30 ║
╟───┼────╢
║ 0 │ 20 ║
╟───┼────╢
║ 4 │ 4 ║
╟───┼────╢
║ 8 │ 4 ║
╟───┼────╢
║ 3 │ 2 ║
╟───┼────╢
║ 2 │ 1 ║
╟───┼────╢
║ 7 │ 0 ║
╚═══╧════╝
Last modified 1yr ago