How do I find numeric columns in Pandas?

Hanan Shteingart picture Hanan Shteingart · Jul 30, 2014 · Viewed 126.5k times · Source

Let's say df is a pandas DataFrame. I would like to find all columns of numeric type. Something like:

isNumeric = is_numeric(df)

Answer

Anand picture Anand · Jan 26, 2015

You could use select_dtypes method of DataFrame. It includes two parameters include and exclude. So isNumeric would look like:

numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']

newdf = df.select_dtypes(include=numerics)