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:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
#1 Best Overall
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:
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 whetherTrueandFalseshould 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:
Rank #4
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.
Recommended Free Tools
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.
Best Value
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.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick 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.




