HOWTO · Pandas
How to Drop Pandas Rows
This tutorial explains how we can drop rows in Pandas using the pandas.DataFrame.drop() method.
On this page
This tutorial shows how to remove rows from a pandas DataFrame with pandas.DataFrame.drop(). The values passed to drop() are index labels. With the default integer index, labels often look like row positions, but a label is not inherently a position. The examples below show how to select labels directly, translate positions into labels, and remove rows that match a column condition.
Run this example:
import pandas as pd
people = pd.DataFrame(
{"Name": ["Himansh", "Prateek", "Abhishek", "Vidit", "Anupam"],
"Age": [30, 33, 35, 30, 30]}
)
remaining = people.drop([0, 2])
print(remaining)
Drop Rows by Index Labels
Pass one label or a list of labels to drop(). In the example above, the default index is 0 through 4, so labels 0 and 2 identify the first and third rows. The returned DataFrame keeps the original labels for the rows that remain; pandas does not renumber them automatically. Use reset_index(drop=True) if a new consecutive index is useful for later work.
For a custom index, pass its actual labels. This independent example uses names as labels, so "A" and "C" select the first and third entries only because those labels were assigned to those rows:
import pandas as pd
people = pd.DataFrame(
{"Name": ["Himansh", "Prateek", "Abhishek", "Vidit", "Anupam"],
"Age": [30, 33, 35, 30, 30]},
index=["A", "B", "C", "D", "E"],
)
remaining = people.drop(["A", "C"])
print(remaining)
A label that is not present raises a KeyError by default. When labels are optional, pass errors="ignore" to skip labels that are absent; use this deliberately because it can also hide a misspelled label.
Drop Rows by Position
drop() accepts labels, not row positions. To remove rows by zero-based position, first select those positions from the index, then pass the resulting labels to drop(). This distinction matters when an index is custom or has been reordered. The example is self-contained:
import pandas as pd
people = pd.DataFrame(
{"Name": ["Himansh", "Prateek", "Abhishek", "Vidit", "Anupam"],
"Age": [30, 33, 35, 30, 30]},
index=["A", "B", "C", "D", "E"],
)
positions = [0, 2]
labels = people.index.take(positions)
remaining = people.drop(labels)
print(remaining)
Here, positions 0 and 2 are translated to labels "A" and "C" before removal. If you already know the labels, use them directly as in the previous section. Position-based selection can also be expressed with iloc when the goal is to keep selected rows rather than remove them.
Drop Rows Based on Column Values
To remove rows that match a condition, find their index labels and pass those labels to drop(). In this example the condition selects ages up to and including 33; the resulting DataFrame therefore retains the people older than 33:
import pandas as pd
people = pd.DataFrame(
{"Name": ["Himansh", "Prateek", "Abhishek", "Vidit", "Anupam"],
"Age": [31, 33, 35, 36, 34]},
index=["A", "B", "C", "D", "E"],
)
remove_labels = people.index[people["Age"] <= 33]
remaining = people.drop(remove_labels)
print(remaining)
This approach is useful when the condition identifies rows to remove. If it is clearer to describe which rows to keep, use Boolean filtering instead, such as people[people["Age"] > 33]. Both approaches return the matching remaining rows for this condition; filtering can be easier to read when the keep rule is the main idea.
Understand DataFrame.drop() Behavior and Common Pitfalls
pandas.DataFrame.drop() returns a new DataFrame by default and leaves the original object unchanged. Assign the result, as each example does, or use the returned value in a later expression. The inplace=True option changes the original object and returns None; assignment such as people = people.drop(...) is generally clearer because it makes the result explicit.
By default, drop() removes labels from the index. For column labels, specify axis="columns" (or columns=[...]); this article uses row labels. Remember that a default integer index can make labels resemble positions, while a custom index makes the distinction visible. If a result surprises you, check people.index, verify that the condition selects the rows intended for removal, and confirm that you retained the result returned by drop().