Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →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"].
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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.
#1 Best Overall
# 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:
Rank #2
# 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.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesUse 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.
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.
Best Value
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.
Quick Recap
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.




