danfo.DataFrame.sort_index(kwargs) [source]
Parameters | Type | Description | Default |
kwargs | Object | { ascending: Order of sorting inplace: specify whether to perform the operation to the row/column with/without creating a new DataFrame } | {ascending: true, inplace:false} |
Returns:
return DataFrame
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.sort_index({ ascending: false })df2.print()
╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ 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 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝