DataFrame.sortIndex
Sort DataFrame by index
Parameters | Type | Description | Default |
---|---|---|---|
options | Object | { ascending: Sorting order. inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false } | {ascending: true, **inplace:**false} |
Returns:
**** return DataFrame
Node
Browser
const dfd = require("danfojs-node")
let data = [[0, 2, 4, "b"],
[360, 180, 360, "a"],
[2, 4, 6, "c"]]
let df = new dfd.DataFrame(data, { "columns": ["col1", "col2", "col3", "col4"],
index: ["b", "a", "c"] })
df.print()
let df2 = df.sortIndex({ ascending: false })
df2.print()
Output
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ col1 │ col2 │ col3 │ col4 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b │ 0 │ 2 │ 4 │ b ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ a │ 360 │ 180 │ 360 │ a ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ c │ 2 │ 4 │ 6 │ c ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
//after sorting in descending order
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ col1 │ col2 │ col3 │ col4 ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ c │ 2 │ 4 │ 6 │ c ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b │ 0 │ 2 │ 4 │ b ║
╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ a │ 360 │ 180 │ 360 │ a ║
╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
Last modified 1yr ago