Studio KimHippo :D

[Python / NumPy] 9. NumPy 연습 1 - 미국 대통령 키 데이터 활용 본문

Python Study/NumPy

[Python / NumPy] 9. NumPy 연습 1 - 미국 대통령 키 데이터 활용

김작은하마 2019. 7. 8. 16:56

필요 패키지 로드

%matplotlib inline

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn 

seaborn.set() # NOTE : 플롯 스타일 설정

미국 대통령 키 추출

data = pd.read_csv('president_heights.csv')
heights = np.array(data['height(cm)']) 

Out [1] :

array([189, 170, 189, 163, 183, 171, 185, 168, 173, 183, 173, 173, 175,

       178, 183, 193, 178, 173, 174, 183, 183, 168, 170, 178, 182, 180,

       183, 178, 182, 188, 175, 179, 183, 193, 182, 183, 177, 185, 188,

       188, 182, 185])

미국 대통령 키 통계치

print('Mean height : ', heights.mean())
print('Standard deviation height : ', heights.std())
print('Variance height : ', heights.var())
print('Mininum height : ', heights.min())
print('Maximum height : ', heights.max()) 

Out [1] :

Mean height :  179.73809523809524

Standard deviation height :  6.931843442745892

Variance height :  48.05045351473922

Mininum height :  163

Maximum height :  193

미국 대통령 키 4분위 수

print("25th percentile : ", np.percentile(heights, 25))
print("Median          : ", np.median(heights))
print("75th percentile : ", np.percentile(heights, 75)) 

Out [1] :

25th percentile :  174.25

Median          :  182.0

75th percentile :  183.0

미국 대통령 키 막대 그래프

plt.hist(heights)
plt.title('Height Distribution of US President')
plt.xlabel('height (cm)')
plt.ylabel('number') 

참고

O'REILLY 제이크 밴더플래스 저/ 위키북스 김정인 역 - 파이썬 데이터 사이언스 핸드북

Comments