User Tools

Site Tools



The idea here is to reset index such that they are all integers from 0 to N.


Two possible approaches:

Use reset_index()

To not modify the original df but assign the result to a new variable

df_new = df.reset_index(drop=True)

To do it in place

df.reset_index(drop=True, inplace=True)

Sample code:

use reindex to directly change the index

df.index = np.arange(len(df))

Sample code:

tags | reindex from 0 to N, range, uses np.arange


set index from 0 to N

See also

set_index_from_0_to_n.txt · Last modified: 2022/03/16 21:55 by raju