수업(국비지원)/Python
[Python] seaborn (조회, 정렬)
byeolsub
2023. 4. 25. 11:46
📌
#1. seaborn 데이터에서 mpg 데이터 로드
import seaborn as sns
mpg = sns.load_dataset("mpg")
mpg.info()
'''
mpg : 연비
cylinders : 실린더 수
displacement : 배기량
horsepower : 출력
weight : 차량무게
acceleration : 가속능력
model_year : 출시년도
origin : 제조국
name : 모델명
'''
#2. 제조국별 자동차 건수 조회하기
#2-1
mpg.origin.value_counts()
#2-2
mpg['origin'].value_counts()
#3. 제조국 컬럼의 값을 조회하기
# unique() : 중복을 제거하여 조회
mpg.origin.unique() #[usa, japan, europe]
#4. 출시년도의 데이터 조회하기
mpg.model_year.unique()
mpg.model_year.value_counts()
#5. mpg 데이터의 통계정보 조회하기
mpg.describe() #숫자형태의 데이터만 조회
mpg.describe(include="all") #모든데이터 조회


📌
type(mpg)
#mpg 데이터의 행의값, 열의 값 조회
mpg.shape #(398,9) 튜플데이터 : 398행 9열
#행의 값만 조회
mpg.shape[0] #튜플에서 0은행 1은열
#열의 값만 조회
mpg.shape[1]
#모든 컬럼의 자료형을 조회하기
mpg.dtypes
#mpg 컬럼의 자료형을 조회하기
mpg["mpg"].dtypes
#6.mpg. 데이터의 mpg,weight 컬럼의 최대값 조회하기
mpg.mpg.max()
mpg.weight.max()
mpg[["mpg","weight"]].max()


#7. mpg데이터의 mpg,weihgt 컬럼의 기술통계 정보 조회하기
mpg[["mpg","weight"]].describe(include="all")
#8. 최대 연비를 가진 자동차의 정보 조회하기
mpg[mpg["mpg"]==mpg["mpg"].max()]
mpg.loc[mpg["mpg"]==mpg["mpg"].max()]
mpg.iloc[mpg["mpg"].idxmax()]
#mpg 데이터의 컬럼간의 상관계수 조회하기
mpg.corr()
# mpg mpg,weight데이터 컬럼간의 상관계수 조회하기
mpg[["mpg","weight"]].corr()