简体   繁体   中英

Python - how to reset the order of number in the column data frame name pandas?

here is my data frame

Student_Id St_Name
1          John
2          Mark
3          Zen
4          David
5          Max
6          Sanny
7          Seolla

and I have removed sum number in this data frame

Student_Id St_Name
2          Mark
4          David
5          Max
7          Seolla

but i would like to re-order it. and the expectation of this output will be

Student_Id St_Name
    1          Mark
    2          David
    3          Max
    4          Seolla

I have tried df.Student_Id.reset_index(). but, it's not working.

Use:

df['Student_Id'] = df.reset_index().index + 1
df

Student_Id  St_Name
1   Mark
2   David
3   Max
4   Seolla

OR

df['Student_Id'] = range(1, df.shape[0]+1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM