How to Drop a List of Rows from a Pandas Dataframe?

Spread the love

Problem –

You want to drop a list of rows from a dataframe in pandas.

Solution –

Read a dataset to work with.

import pandas as pd

url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/LargeCorp.csv'
df = pd.read_csv(url)
df.head()

Let’s say you want to drop the rows with index 2 and 3. To do that you have to use the drop method and pass the index of the rows that you want to drop.

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

Rating: 1 out of 5.

Leave a Reply