Categories
Python Answers

How to drop a list of rows from a Python Pandas dataframe?

Spread the love

Sometimes, we want to drop a list of rows from a Python Pandas dataframe.

In this article, we’ll look at how to drop a list of rows from a Python Pandas dataframe.

How to drop a list of rows from a Python Pandas dataframe?

To drop a list of rows from a Python Pandas dataframe, we can use the data frame drop method.

For instance, we write

df.drop(df.index[[1, 3]])

to call df.drop to drop the items with index between 1 and 3 with df.index[[1, 3].

A new data frame will be returned with the rows dropped.

Conclusion

To drop a list of rows from a Python Pandas dataframe, we can use the data frame drop method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *