Python | Pandas dataframe.select_dtypes ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas 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)
Parameters :
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.
Для ссылки на CSV-файл, используемый в коде, щелкните здесь
Example #1: Use select_dtypes() function to select all the columns which are having floating data types.
# importing pandas as pdimport pandas as pd # Creating the dataframe df = pd.read_csv("nba.csv") # Print the dataframedf |

Let’s use the dataframe.select_dtypes() function to select all columns having float data type in the dataframe.
# select all columns having float datatypedf.select_dtypes(include ="float64") |
Output :
Example #2: Use select_dtypes() function to select all the columns in the dataframe except those columns which are of float data type.
# importing pandas as pdimport pandas as pd # Creating the dataframe df = pd.read_csv("nba.csv") # select all columns except float baseddf.select_dtypes(exclude ="float64") |
Выход :
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.