October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober 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

How to Drop Rows in Pandas Based on Column Values

Use a Boolean mask to keep the rows you want, invert it to exclude matches, and use isin for a list of exact values.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To remove rows based on a column value, build a Boolean condition that selects the rows you want to keep. For example, use df[df["status"] != "inactive"] to exclude rows whose status is "inactive". For a list of values, use ~df["status"].isin([...]).

Filter rows by a column condition

Pandas Boolean indexing selects rows wherever a condition evaluates to True. To drop rows that match a condition, write the opposite condition and select the rows that remain.

As an Amazon Associate I earn from qualifying purchases.

# Keep rows whose status is not inactive
active = df[df["status"] != "inactive"]

# Keep rows where age is at least 18
adults = df[df["age"] >= 18]

These expressions return a filtered DataFrame; they do not change df itself. If you want to replace the original variable, assign the result back to it: df = df[df["status"] != "inactive"].

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

Exclude several exact values with isin

Use Series.isin when the rows to remove have one of several exact values. It returns a Boolean Series, and ~ inverts that mask so the selection keeps values outside the list.

# Exclude both inactive and archived rows
active = df[~df["status"].isin(["inactive", "archived"])]

This is clearer than chaining many equality checks. The values are matched against the column as supplied; use values with the appropriate types and spelling for your data.

Combine multiple conditions

Use & for AND, | for OR, and ~ for NOT when combining Boolean Series. Put parentheses around each comparison:

# Keep rows meeting both conditions
kept = df[(df["score"] >= 70) & (df["status"] != "withdrawn")]

# Keep rows meeting either condition
kept = df[(df["score"] >= 70) | (df["status"] == "review")]

# Exclude rows matching a condition
kept = df[~(df["status"] == "withdrawn")]

Do not use Python’s and or or between Series conditions; use the bitwise operators shown above. Parentheses make each comparison explicit and avoid operator-precedence surprises.

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

Use query for a compact expression

DataFrame.query offers a string-based alternative for conditions that read naturally as expressions over column names.

adults = df.query("age >= 18")
active = df.query('status not in ["inactive", "archived"]')

Like Boolean indexing, query returns the selected rows by default; its API also supports an inplace option. The pandas documentation describes it as a way to “Query the columns of a DataFrame with a boolean expression.” Do not construct query strings from untrusted user input: query expressions can run arbitrary code. For dynamically supplied criteria, prefer a Boolean mask.

Choose the operation that matches what you want to remove

Goal Use Example
Remove rows because a column value meets a condition Boolean indexing or query df[df["age"] >= 18] keeps qualifying rows
Remove rows with one of several exact values isin with an inverted mask df[~df["status"].isin(["inactive", "archived"])]
Remove rows with known index labels DataFrame.drop df.drop(index=[2, 5])
Remove rows with missing values in selected columns DataFrame.dropna df.dropna(subset=["status"])

Column values: filter with a mask

This is the usual choice for a predicate such as “age is under 18” or “status is archived.” The condition examines column values and determines which rows to retain.

Index labels: use drop

DataFrame.drop removes axis labels, not rows selected by a value test. It defaults to rows and returns a new DataFrame unless inplace=True. If a requested label is missing, it raises KeyError by default.

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

Missing values: use dropna

DataFrame.dropna is specifically for missing data. Use subset to limit the check to particular columns; its how and thresh options control how missingness is assessed. It is not a general-purpose condition filter.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What happens to the index?

Boolean selection keeps the original index labels for the rows that remain. Filtering does not automatically renumber them. If you need a fresh consecutive index for display or export, reset it as a separate step, for example active = active.reset_index(drop=True).

Documentation and version notes

The official pandas documentation covers Boolean indexing and selection, Series.isin, DataFrame.query, DataFrame.drop, and DataFrame.dropna. Documentation behavior and available options can vary by pandas release; consult the version installed in your environment if a version-specific detail matters.

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 *

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.

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
PC Slower Than It Used to Be?Free scan - under a minute

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.