일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 응시료
- 빅데이터 분석기사
- separating data(데이터 분리하기)
- matplotlib
- Seaborn
- 준비
- List Comprehension
- context manger1
- teen learn
- pythonML
- 시험 일정
- K 데이터 자격시험
- 검정수수료
- numpy
Archives
- Today
- Total
재원's 블로그
Missing value2 (결측치2) 본문
최초 작성일 : 2021-12-22
categories: Python
Missing Value : 결측치 확인
data loading
import pandas as pd
covidtotals = pd.read_csv("../input/covid-data/covidtotals.csv")
covidtotals.head()
<실행 화면>
data info
covidtotals.info()
<실행 화면>
data division
● 인구통계 관련 column
● Covid 관련 column
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별로 결측치를 측정
covidtotals[demo_vars].isnull().sum(axis = 0) # column별로 결측치를 측정
<실행 화면>
case_vars column별로 결측치를 측정
covidtotals[case_vars].isnull().sum(axis = 0) # column별로 결측치를 측정
<실행 화면>
● case_vars 에는 결측치가 없지만, demo_vars에는 결측치가 있는 것을 확인 할 수 있다.
위의 column들에 각각 수만큼의 결측치를 확인 할 수 있다.
행 방향으로 발생한 결측치 확인
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
covidtotals[case_vars].isnull().sum(axis = 1).value_counts()
<실행 화면>
0 210
dtype: int64
인구통계 데이터가 3가지 이상 누락된 국가를 나열하기
["location"] + demo_vars
covidtotals.loc[demovars_misscnt >= 3, ["location"] + demo_vars].T
<실행 화면>
case에는 누락국가가 없지만, 한번 확인
casevars_misscnt = covidtotals[case_vars].isnull().sum(axis = 1)
casevars_misscnt.value_counts()
<실행 화면>
0 210
dtype: int64
covidtotals[covidtotals['location'] == "Hong Kong"]
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)
<실행 화면>
위의 사진은 결측치가 있는지 없는지를 확인 시켜주는 사진이다.
'Python' 카테고리의 다른 글
crawlig2 (크롤링2) (0) | 2023.01.23 |
---|---|
python def, decorator (0) | 2023.01.23 |
Missing value (결측치) (0) | 2023.01.23 |
Order & Find outliers(주문과 이상치 찾기) (0) | 2023.01.23 |
Trees - Decision Tree about(결정 트리에 대해) (0) | 2023.01.23 |