df.reset_index(
drop=True,# to avoid the old index being added as a column
inplace=False)# (default) return df with the new index, i.e. do not create a new object
import pandas as pd
data ={'Name':['Bob','Dilan','is ','alive','!']}
index ={'a','b','c','d','e'}
df = pd.DataFrame(data, index)
df
Name
b Bob
a Dilan
d is
c alive
e !
df.reset_index(inplace =True)
df
index Name
0 b Bob
1 a Dilan
2 d is3 c alive
4 e !
Reset Index & Retain Old Index as Column in pandas
import pandas as pd
#define DataFrame
df = pd.DataFrame({'points':[25,12,15,14,19,23,25,29],'assists':[5,7,7,9,12,9,9,4],'rebounds':[11,8,10,6,6,5,9,12]},
index=['A','C','D','B','E','G','F','H'])#view DataFrameprint(df)
points assists rebounds
A 25511
C 1278
D 15710
B 1496
E 19126
G 2395
F 2599
H 29412