DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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 Now×
Skip to content
World desk3 min

How to Drop Non-Numeric Columns from a pandas DataFrame

Filter pandas columns by their stored dtype with select_dtypes. Keep numeric data with include="number" or retain non-numeric fields with exclude="number".
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To keep only numeric columns in a pandas DataFrame, use df.select_dtypes(include=["number"]). To keep only non-numeric columns, use df.select_dtypes(exclude=["number"]). The method returns a filtered DataFrame; assign it to a variable or back to df to use the result.

Keep only numeric columns

Use include when your goal is to drop non-numeric columns and retain the numeric data:

As an Amazon Associate I earn from qualifying purchases.

numeric = df.select_dtypes(include=["number"])

To replace the existing DataFrame variable with that subset:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
df = df.select_dtypes(include=["number"])

select_dtypes selects columns according to their stored data types, not by inspecting whether their values look numeric. The pandas API describes it as returning a subset of a DataFrame’s columns based on their dtypes: DataFrame.select_dtypes.

Keep only non-numeric columns instead

If you literally want to drop numeric columns and preserve everything else, use exclude:

non_numeric = df.select_dtypes(exclude=["number"])

For example, the result can retain text or other non-numeric fields while leaving numeric columns out. The name you assign to the result is up to you; the selection itself does not modify df unless you assign it back.

Check why a column was not selected

Inspect the dtype pandas assigned to each column:

print(df.dtypes)

The output is indexed by the original column labels. A column with mixed values may have the object dtype, and a column of digit-containing strings is still text for dtype selection. If those values are intended to be quantities, convert the column before selecting:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
df["amount"] = pd.to_numeric(df["amount"], errors="coerce")
numeric = df.select_dtypes(include=["number"])

With errors="coerce", values that cannot be parsed become missing values. Use that option only if this treatment of invalid entries is acceptable. The pandas.to_numeric documentation also notes that precision loss can occur for very large values.

Decide how to handle booleans and time-based columns

Do not assume every dtype that has a numeric-looking representation belongs in a numeric-only result. Choose the treatment according to what the values mean:

  • Booleans: pandas supports selecting boolean columns explicitly with include="bool". Decide whether True and False should count as numeric for your task; do not rely on an unstated assumption.
  • Datetime and timedelta: these are distinct from ordinary numeric dtypes in the documented numeric dtype checks. If you need elapsed time or timestamps as numeric quantities, transform them deliberately.
  • Categoricals and timezone-aware dates: these use their own dtype families. Some pandas-specific dtypes do not follow the usual NumPy dtype hierarchy, so check the actual dtype and test the selection when the distinction matters.

For per-column logic, a dtype predicate is another option:

from pandas.api.types import is_numeric_dtype

numeric = df.loc[:, df.dtypes.apply(is_numeric_dtype)]

The is_numeric_dtype API documents the predicate for checking whether an array or dtype is numeric. For a straightforward subset, select_dtypes(include="number") is simpler.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle empty results and summary-only work

If no columns match the requested dtype selection, the result can have zero columns. Code that processes DataFrames with variable schemas should account for that possibility before relying on a selected column.

If you only need descriptive statistics for non-numeric columns—not a filtered DataFrame for later operations—use:

df.describe(exclude=["number"])

This summarizes the non-numeric columns; select_dtypes is the choice when subsequent code needs the filtered columns. See the DataFrame.describe documentation.

Check the documentation for your pandas version

The current pandas API page cited here is for pandas 3.0.6, and the versioned pandas 2.0.3 API documentation describes the same core include/exclude approach: pandas 2.0.3 DataFrame.select_dtypes. This does not establish behavior for every older release, so check the documentation corresponding to the pandas version installed in your environment.

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