What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use DataFrame.drop() to remove named labels from a pandas DataFrame’s index or columns. Prefer df.drop(index=...) for rows and df.drop(columns=...) for columns. By default, pandas returns a new DataFrame and raises a KeyError if a requested label is missing.
What does DataFrame.drop() do?
The pandas API describes DataFrame.drop() as dropping specified labels from rows or columns. It is label-based: it removes index or column labels, not rows identified by their numeric position. The official API reference is the DataFrame.drop documentation.
The default target is the index, or row axis (axis=0). Use axis=1 to target columns. The more explicit index= and columns= arguments are usually easier to read and less likely to cause an axis mix-up.
How do I drop a row from a pandas DataFrame?
Pass the row’s index label to index=. For example, if the index labels are 0, 1, and 2, this removes the rows labeled 0 and 2:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
without_rows = df.drop(index=[0, 2])
If your DataFrame uses a custom index, pass those labels instead. For instance, df.drop(index="customer_17") removes the row with that index label; it does not mean “remove the seventeenth row.”
How do I drop a column in pandas?
Pass column names to columns=. A list removes multiple columns in one call:
Rank #2
without_columns = df.drop(columns=["temporary", "unused"])
The equivalent axis-based form is df.drop(["temporary", "unused"], axis=1). The columns= form makes the target explicit, which helps prevent accidentally dropping row labels.
What does drop() return?
With the default inplace=False in the stable API reference, drop() returns a DataFrame with the requested labels removed; the original variable is not reassigned automatically. Keep the result by assigning it:
df = df.drop(columns=["temporary"])
The stable reference documents inplace=True as modifying the object and returning None. Therefore, avoid assigning the result of an inplace call: df = df.drop(columns=["temporary"], inplace=True) makes df equal to None.
Version note: the pandas 3.1.0 development reference marks inplace as deprecated since 3.1.0 and says it will be removed in pandas 4.0. This is a development-reference statement, not a guarantee about every installed release. Check the pandas 3.1 development API reference and the documentation for your installed version when version compatibility matters.
Why does DataFrame.drop() raise a KeyError?
By default, pandas raises KeyError when a requested label is not present on the selected axis. This often catches a misspelled name or a column that has already been removed. Keep the default behavior when a missing label should signal a problem.
If absence is expected—for example, when applying the same cleanup list to DataFrames that do not all contain the same columns—use errors="ignore":
Recommended Free Tools
Best Value
without_columns = df.drop(
columns=["temporary", "possibly_absent"],
errors="ignore"
)
This removes any listed columns that exist and does not raise an error for missing ones. The same option works when dropping index labels.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.How do labels, axes, and MultiIndex work?
The reference signature is DataFrame.drop(labels=None, *, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise') in the stable API documentation. labels is interpreted against the axis selected by axis; a tuple is treated as one label, not as a list-like collection of labels.
For a MultiIndex, use level= to specify which level’s matching labels should be removed. That removes matching entries from the DataFrame; it is different from removing a level from the index structure itself. For the latter, use droplevel().
Quick Recap
Which pandas method should I use instead?
| Goal | Method | What it does |
|---|---|---|
| Remove known row or column labels | drop() |
Removes explicitly named labels from an axis. pandas API reference |
| Remove rows or columns based on missing values | dropna() |
Selects according to NA presence, with options such as how, thresh, and subset. pandas API reference |
| Remove duplicate rows | drop_duplicates() |
Selects duplicates, optionally using a subset of columns and a choice of which copy to keep. pandas API reference |
| Change axis labels rather than remove them | rename() |
Renames index or column labels. pandas API reference |
| Remove a level from an index or column axis | droplevel() |
Removes level structure; drop(level=...) instead removes matching labels from a level. pandas API reference |
| Replace the index with a default integer index | reset_index() |
Resets the index and can optionally discard the old index values. pandas API reference |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




