Pandas 결측치 처리 - isnull, fillna, dropna
Pandas 결측치 처리 - isnull, fillna, dropna
Pandas 결측치 처리 - isnull, fillna, dropna
데이터 분석
copy
- DataFrame을 복제
- 복제한 DataFrame을 수정해도 원본에는 영향을 미치지 않음
df_copy = df.copy()
결측치
- 결측치 처리
- 결측치 데이터 확인
- 결측치가 아닌 데이터 확인
- 결측 데이터 채우기
- 결측 데이터 제거하기
- 결측치 확인
isnull(),isna()df.isnull().sum(): 결측치 개수 확인
- 결측치 아닌 데이터 확인
notnull()df.notnull().sum(): 결측치 아닌 개수 확인
- 결측치 데이터 필터링
df.loc[df['age'].isnull()]
- 결측치 채우기
- 특정값으로 채우기
fillna()df1['age'].fillna(700)
- 통계값으로 채우기
df1['age'].fillna(df1['age'].mean())
- 특정값으로 채우기
- NaN 값이 있는 데이터 제거
df1.dropna(): 1개라도 Nan값이 있는 행제거df1.dropna(how='all'): 모두 NaN값일시 행제거
This post is licensed under CC BY 4.0 by the author.