Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have a data frame from which I remove some rows. As a result, I get a data frame in which index is something like that: [1,5,6,10,11] and I would like to reset it to [0,1,2,3,4]. How can I do it?

The following seems to work:

df = df.reset_index()

del df['index']

The following does not work:

df = df.reindex()

1 Answer

0 votes
by (41.4k points)

Use reset_index() :

df = df.reset_index(drop=True)

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 31, 2019 in Data Science by sourav (17.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...