-
[전처리, Preprocessing] 결측값 처리_1(열 삭제)파이썬, Python/[AI] 인공지능 - 머신러닝, ML 2020. 2. 2. 22:57728x90
결측값 처리방법¶
- 결측값이 있는 Column(열) 전체를 삭제(Drop)
- 심플하게 결측값을 처리할 수 있으나, 다량의 정보가 손실됨
In [76]:from IPython.core.display import display, HTML display(HTML("<style>.container { width:100% !important;}</style>")) # 1. Drop ## 1) 결측값이 있는 Column 찾아내기 import pandas as pd import numpy as np df = pd.DataFrame(np.arange(12).reshape(3, 4), columns=['A', 'B', 'C', 'D']) #df.A.dropna() df.C[2] = None df
Out[76]:In [64]:cols_with_missing = [col for col in df.columns if df[col].isnull().any()] # 만약, X_train Column 값중 null 값이 하나라도 있을경우 # 해당 Column을 col에 넣어서 반복 > [col1, col2, ...] reduced_df = df.drop(cols_with_missing, axis=1) #axis=0이 Default값이며, 행을 의미함. axis=1은 열을 의미 reduced_df
Out[64]:In [ ]:반응형'파이썬, Python > [AI] 인공지능 - 머신러닝, ML' 카테고리의 다른 글
Keras custom loss 만들기 (0) 2020.08.06 [Machine Learning] 모델 과적합(overfitting) 확인 (0) 2020.07.07 [Machine Learning] Deep Learning for anomaly detection(survey)_1편 (0) 2020.05.30 [Python] 웹크롤링 Tool (0) 2020.04.24 Pipeline (0) 2020.02.04 - 결측값이 있는 Column(열) 전체를 삭제(Drop)