🍅빅데이터 분석기사/정리

숫자형 컬럼만 뽑아서 상관계수 구하기 select_dtypes(include = ' ')

류딩이 2025. 6. 15. 17:55
import numpy as np
import pandas as pd 

df = pd.read_csv('/kaggle/input/bigdata-csvfile/Sleep_health_and_lifestyle_dataset.csv')

df = df.select_dtypes(include = 'numbers')
corr = df.corr()

 

df.select_dtypes(include='number')  # 숫자형 컬럼만 추출
df.select_dtypes(include='object')  # 문자형 컬럼만 추출
df.select_dtypes(include='category')  # 범주형만 추출

# 여러 타입도 선택 가능

df.select_dtypes(include=['int64', 'float64'])
댓글수0