October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Pandas DataFrame drop(): Remove Rows and Columns by Label

Use pandas DataFrame.drop() to remove index or column labels, handle missing-label KeyErrors, and choose the right method for rows, columns, NA values, and duplicates.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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:

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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":

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.Support on Ko-Fi

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().

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.