Pandas select_dtypes() method returns a subset of the DataFrame’s columns based on the column dtypes. You can include or exclude columns based on their dtypes.
Let’s read a dataset.
import pandas as pd url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/clothing_store_sales.csv' df = pd.read_csv(url) df.head()
We can check the data types of each columns using the dtype method.
Including Columns –
Let’s say that you want to select all integer columns from your dataframe.
Excluding Columns –
You can also exclude columns using the exclude parameter. Let’s say you want to exclude all integer and float columns.