Back

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

I think this should be simple, but I tried a few ideas and none of them worked:

last_row = len(DF)

DF = DF.drop(DF.index[last_row])  #<-- fail!

I tried using negative indices but that also lead to errors. I must still be misunderstanding something basic. 

Thanks in advance.

1 Answer

0 votes
by (41.4k points)
edited by

dropping last n rows:

df.drop(df.tail(n).index,inplace=True) # drop last n rows

Similarly, you can drop first n rows:

df.drop(df.head(n).index,inplace=True) # drop first n rows

To Learn What is Data Science and how to be a data scientist visit the data science Courses by Intellipaat.

Browse Categories

...