§ 결측치 찾기 이론
§ 결측치 찾기 실습
§ 변수 1개를 이용하여 이상값 찾기
§ 변수 2개를 이용하여 이상값 찾기
♠ Ref.01
data in Kaggle
note를 public으로 올려는 놨는데 검색이 될까 모르겠네요.
Missing Value : 결측치 확인
data Loading
1 2 3
| import pandas as pd covidtotals = pd.read_csv("../input/covid-data/covidtotals.csv") covidtotals.head()
|

data info

data division
- 인구통계 관련 column
- Covid 관련 column
1 2
| case_vars = ["location", "total_cases", "total_deaths", "total_cases_pm", "total_deaths_pm"] demo_vars = ["population", "pop_density", "median_age", "gdp_per_capita", "hosp_beds"]
|
demo_vars column별로 결측치를 측정
1
| covidtotals[demo_vars].isnull().sum(axis = 0)
|

case_vars column별로 결측치를 측정
1
| covidtotals[case_vars].isnull().sum(axis = 0)
|

- case_vars 에는 결측치가 없지만, demo_vars에는 결측치가 있는 것을 확인 할 수 있다.
|
|
|
|
|
pop_density |
|
12 |
|
|
median_age |
|
24 |
|
|
gdp_per_capita |
|
28 |
|
|
hosp_beds |
|
46 |
|
|
위의 column들에 각각 수만큼의 결측치를 확인 할 수 있다.
행 방향으로 발생한 결측치 확인
1 2
| demovars_misscnt = covidtotals[demo_vars].isnull().sum(axis = 1) demovars_misscnt.value_counts()
|
0 156
1 24
2 12
3 10
4 8
dtype: int64
1
| covidtotals[case_vars].isnull().sum(axis = 1).value_counts()
|
0 210
dtype: int64
인구통계 데이터가 3가지 이상 누락된 국가를 나열하기
1 2 3
| ["location"] + demo_vars covidtotals.loc[demovars_misscnt >= 3, ["location"] + demo_vars].T
|

case에는 누락국가가 없지만, 그냥 한번 확인
1 2
| casevars_misscnt = covidtotals[case_vars].isnull().sum(axis = 1) casevars_misscnt.value_counts()
|
0 210
dtype: int64
1
| covidtotals[covidtotals['location'] == "Hong Kong"]
|
1 2 3 4 5 6
| temp = covidtotals.copy() temp[case_vars].isnull().sum(axis = 0) temp.total_cases_pm.fillna(0, inplace = True) temp.total_deaths_pm.fillna(0, inplace = True) temp[case_vars].isnull().sum(axis = 0)
|

이건 잘 모르겠다. 그냥 삭제 할 수 있다.