Series.reset_index

Reset the index of a series.

danfo.series.reset_index(kwargs) [source]

Generate a new Series with the index reset. This is useful when the index needs to be treated as a column, or when the index is meaningless and needs to be reset to the default before another operation.

Parameters

Type

Description

Default

kwargs

Object

kwargs is an object {} with key inplace with a boolean value. e.g {inplace: false}

inplace:false

Returns : Series

Example

Node
Browser
Node
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)
let sf_new = sf.set_index({ "index": ["one", "two", "three"] })
let sf_reset = sf_new.reset_index()
sf_reset.print()
Browser
Output
Output
╔═══╤══════════════════════╗
║ │ 0 ║
╟───┼──────────────────────╢
║ 0 │ {"alpha":"A","cou... ║
╟───┼──────────────────────╢
║ 1 │ {"alpha":"B","cou... ║
╟───┼──────────────────────╢
║ 2 │ {"alpha":"C","cou... ║
╚═══╧══════════════════════╝
Node
Browser
Node
const dfd = require("danfojs-node")
let data = [1,2,3,4,5,6]
let sf = new dfd.Series(data)
sf.set_index({ "index": ["one", "two", "three", "four", "five", "six"], "inplace": true })
let sf_reset = sf.reset_index()
sf_reset.print()
Browser
Output
Output
╔═══╤══════════════════════╗
║ │ 0 ║
╟───┼──────────────────────╢
║ 0 │ 1 ║
╟───┼──────────────────────╢
║ 1 │ 2 ║
╟───┼──────────────────────╢
║ 2 │ 3 ║
╟───┼──────────────────────╢
║ 3 │ 4 ║
╟───┼──────────────────────╢
║ 4 │ 5 ║
╟───┼──────────────────────╢
║ 5 │ 6 ║
╚═══╧══════════════════════╝

Reset index without returning a new Series

Node
Browser
Node
const dfd = require("danfojs-node")
let data = [1,2,3,4,5,6]
let sf = new dfd.Series(data)
sf.set_index({ "index": ["one", "two", "three", "four", "five", "six"], "inplace": true })
sf.reset_index({"inplace":true})
sf.print()
Browser
Output
Output
╔═══╤══════════════════════╗
║ │ 0 ║
╟───┼──────────────────────╢
║ 0 │ 1 ║
╟───┼──────────────────────╢
║ 1 │ 2 ║
╟───┼──────────────────────╢
║ 2 │ 3 ║
╟───┼──────────────────────╢
║ 3 │ 4 ║
╟───┼──────────────────────╢
║ 4 │ 5 ║
╟───┼──────────────────────╢
║ 5 │ 6 ║
╚═══╧══════════════════════╝