Links

DataFrame.sortValues

Sort a Dataframe in ascending or descending order by a specified column name.
danfo.DataFrame.sortValues(by, options) [source]
Parameters
Type
Description
Default
by
Object
This key can be either a single column name or a single array of the same length as the calling DataFrame.
options
Object
Optional configuration:
ascending: Order of sorting
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{
ascending: true, inplace: false
}

Examples

Sort DataFrame by a column in ascending order

Node
Browser
const dfd = require("danfojs-node")
let data = {
"A": [-20, 30, 47.3],
"B": [34, 5, 6],
"C": [20, 3, 30]
}
let df = new dfd.DataFrame(data)
df.sortValues("C", { inplace: true })
df.print()
Output
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30 │ 5 │ 3 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ -20 │ 34 │ 20 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ 47.3 │ 6 │ 30 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝

Sort DataFrame by a column in descending order

Node
Browser
const dfd = require("danfojs-node")
let data = { "A": [-20, 30, 47.3],
"B": [34, 5, 6],
"C": [20, 3, 30] }
let df = new dfd.DataFrame(data)
df.sortValues("C", { ascending: false, inplace: true })
df.print()
Output
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ 47.3 │ 6 │ 30 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 2 │ -20 │ 34 │ 20 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ 30 │ 5 │ 3 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝