Powered By GitBook
Series.reset_index
Reset the index of a series.
danfo.series.reset_index(options) [source]
Parameters
Type
Description
Default
options
Object
inplace: Boolean indicating whether to perform the operation inplace or not. Defaults to false
{ inplace:false}
Returns : Series
reset_index is useful when the index needs to be treated as a column, or when the index is meaningless and needs to be reset to default, before another operation.

Reset index to default values

Node
Browser
1
const dfd = require("danfojs-node")
2
let data = [20, 30, 40]
3
let sf = new dfd.Series(data, { index: ["a", "b", "c"] })
4
sf.print()
5
6
let sf_reset = sf.reset_index()
7
sf_reset.print()
Copied!
1
Copied!
Output
1
╔═══╤════╗
2
║ a │ 20 ║
3
╟───┼────╢
4
║ b │ 30 ║
5
╟───┼────╢
6
║ c │ 40 ║
7
╚═══╧════╝
8
9
╔═══╤════╗
10
║ 0 │ 20 ║
11
╟───┼────╢
12
║ 1 │ 30 ║
13
╟───┼────╢
14
║ 2 │ 40 ║
15
╚═══╧════╝
Copied!

Reset index to new values in-place

Node
Browser
1
let data = [1, 2, 3, 4, 5, 6]
2
let sf = new dfd.Series(data, { index: ['a', 'b', 'c', 'd', 'e', 'f'] })
3
sf.print()
4
5
sf.reset_index({ inplace: true })
6
sf.print()
7
Copied!
1
Copied!
Output
1
╔═══╤═══╗
2
║ a │ 1 ║
3
╟───┼───╢
4
║ b │ 2 ║
5
╟───┼───╢
6
║ c │ 3 ║
7
╟───┼───╢
8
║ d │ 4 ║
9
╟───┼───╢
10
║ e │ 5 ║
11
╟───┼───╢
12
║ f │ 6 ║
13
╚═══╧═══╝
14
15
╔═══╤═══╗
16
║ 0 │ 1 ║
17
╟───┼───╢
18
║ 1 │ 2 ║
19
╟───┼───╢
20
║ 2 │ 3 ║
21
╟───┼───╢
22
║ 3 │ 4 ║
23
╟───┼───╢
24
║ 4 │ 5 ║
25
╟───┼───╢
26
║ 5 │ 6 ║
27
╚═══╧═══╝
Copied!
Last modified 24d ago