Shreyas Kulkarni
Shreyas' Blog

Follow

Shreyas' Blog

Follow

How to find the count of only numeric columns in Pandas DataFrame?

Shreyas Kulkarni's photo
Shreyas Kulkarni
ยทOct 30, 2021ยท

1 min read

How to find the count of only numeric columns in Pandas DataFrame?
Play this article

Often times we have 100+ columns in the dataset and we have to find out how many columns are numeric and ultimately count of the columns

numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
numeric_df = df.select_dtypes(include=numerics)
len(numeric_df.columns)

Here, the first line creates a list of all the data types having numeric values and saves them into a variable called numerics

then numeric_df variable stores column for elements stated in numerics variable.

Simply, in the last, we are using the simple len function to calculate the number of columns.

ย 
Share this