Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 Scan×
Skip to content
World desk2 min

How to Drop Rows with NaN Values in Pandas

Use pandas DataFrame.dropna() to remove rows with missing values, with options to control which columns and how many observed values are required.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use df.dropna() to remove every row in a pandas DataFrame that contains at least one value pandas recognizes as missing. It returns a new DataFrame and leaves the original unchanged unless you use inplace=True.

Drop rows that contain any missing value

The default behavior removes a row if even one of its values is missing:

As an Amazon Associate I earn from qualifying purchases.

cleaned = df.dropna()

Assign the result back to df if you want to keep using that variable name:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
df = df.dropna()

By default, the surviving rows keep their existing index labels. To give them a fresh sequential index instead, use ignore_index=True (available for DataFrame.dropna since pandas 2.0.0). See the pandas DataFrame.dropna API reference.

Choose which rows to remove

Use the rule that matches your data-cleaning goal. These options apply to rows unless you set a different axis.

Goal Code Effect
Drop a row if any value is missing df.dropna() or df.dropna(how="any") Removes rows with one or more missing values.
Drop only rows where every value is missing df.dropna(how="all") Keeps rows that have at least one observed value.
Check only required columns df.dropna(subset=["name", "toy"]) Removes rows missing a value in either listed column; other columns do not determine whether the row is kept.
Require a minimum number of observed values df.dropna(thresh=2) Keeps rows with at least two non-missing values.

thresh cannot be combined with how. The documented interface uses keyword-only parameters, so write arguments by name rather than relying on their position. For example:

cleaned = df.dropna(axis=0, subset=["required_column"])

The default axis is rows (axis=0). To remove columns containing missing values instead, use df.dropna(axis="columns"); with its default how="any", a column is dropped if it contains at least one missing value. These behaviors and options are documented in the pandas DataFrame.dropna API reference.

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

What counts as a missing value?

dropna removes values pandas recognizes as missing, including np.nan, pd.NaT, and None. An empty string ("") is not automatically treated as missing, so a row containing one will not be dropped for that reason alone. If you are unsure how pandas interprets values in your data, inspect them with isna(). The pandas Series.dropna documentation demonstrates these missing-value cases.

Keep rows while handling missing values

Dropping rows reduces the observations available for later analysis. If you need to retain rows, DataFrame.fillna can replace missing values with a scalar or a mapping from column names to replacement values. Choose replacements based on what each value means in your data; zero is not a safe default unless zero is meaningful. See the pandas DataFrame.fillna API reference.

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

Assign the result or use inplace=True

By default, df.dropna() returns a DataFrame and does not change df. Prefer assigning the result when you want to retain the cleaned data. With inplace=True, pandas modifies the DataFrame and returns None:

df.dropna(inplace=True)

Do not assign that call back to df: df = df.dropna(inplace=True) would replace the variable with None.

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

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.