Series.setIndex

Assign new Index to Series

danfo.series.setIndex**(options)**

Parameter
Type
Description
Default

index

Array

new index values

options

Object

inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false

{

inplace: false

}

Returns: Series

Example

const dfd = require("danfojs-node")

let data = [{ alpha: "A", count: 1 }, { alpha: "B", count: 2 }, { alpha: "C", count: 3 }]
let sf = new dfd.Series(data)
sf.print()

let sf_new = sf.setIndex(["one", "two", "three"])
sf_new.print()
╔═══╤═════════════════════════╗
║ 0 │ {"alpha":"A","count":1} ║
╟───┼─────────────────────────╢
║ 1 │ {"alpha":"B","count":2} ║
╟───┼─────────────────────────╢
║ 2 │ {"alpha":"C","count":3} ║
╚═══╧═════════════════════════╝

╔═══════╤═════════════════════════╗
║ one   │ {"alpha":"A","count":1} ║
╟───────┼─────────────────────────╢
║ two   │ {"alpha":"B","count":2} ║
╟───────┼─────────────────────────╢
║ three │ {"alpha":"C","count":3} ║
╚═══════╧═════════════════════════╝

Set index in-place

Last updated

Was this helpful?