Python | Pandas dataframe.select_dtypes()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.select_dtypes() function return a subset of the DataFrame’s columns based on the column dtypes. The parameters of this function can be set to include all the columns having some specific data type or it could be set to exclude all those columns which has some specific data types.
Syntax : DataFrame.select_dtypes(include=None, exclude=None)
include, exclude : A selection of dtypes or strings to be included/excluded. At least one of these parameters must be supplied.
Return : The subset of the frame including the dtypes in include and excluding the dtypes in exclude.
For link to the CSV file used in the code, click here
Example #1: Use
select_dtypes() function to select all the columns which are having floating data types.
Let’s use the
dataframe.select_dtypes() function to select all columns having float data type in the dataframe.
Example #2: Use
select_dtypes() function to select all the columns in the dataframe except those columns which are of float data type.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course