DataFrame.setIndex
Set the DataFrame index using existing columns or an array (of the equal length).
Parameters
Type
Description
Default
Examples
Setting index to a column in the DataFrame
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, {index: ["a", "b", "c"]})
df.print()
df.setIndex({column: "A", inplace: true})
df.print()╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ a │ -20 │ 34 │ 20 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ b │ 30 │ 5 │ 3 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ c │ 47.3 │ 6 │ 30 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ A │ B │ C ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ -20 │ -20 │ 34 │ 20 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 30 │ 30 │ 5 │ 3 ║
╟────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 47.3 │ 47.3 │ 6 │ 30 ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╝Setting index to a column in the DataFrame and dropping the column
Set index to an array of the same length
Last updated