Selecting Only Numeric Columns in a Pandas Dataframe

By Hemanta Sundaray on 2021-09-06

Let's read an Excel worksheet into a pandas dataframe:

import pandas as pd

data = pd.read_excel("budget.xlsx")

data

Output:

Data

We can select only the columns that contain numeric values (Revenue & Profit) using the select_dtypes() method and passing the string number to the include parameter.

data.select_dtypes(include="number").head()

Output:

Numeric Columns

Join the Newsletter