Pythonで学ぶクレジットリスクモデリング
Michael Crabtree
Data Scientist, Ford Motor Company
''| 欠損データの種類 | 可能な結果 |
|---|---|
| 数値列の NULL | エラー |
| 文字列列の NULL | エラー |
| 欠損データ | 解釈 | 対応 |
|---|---|---|
loan_status の NULL |
直近で承認されたローン | 予測用データから除外 |
person_age の NULL |
年齢未記録・非開示 | 中央値で補完 |
isnull() で欠損値を検出sum() で欠損件数を集計.any() は全列をチェックnull_columns = cr_loan.columns[cr_loan.isnull().any()]
cr_loan[null_columns].isnull().sum()
# 列ごとの欠損値合計
person_home_ownership 25
person_emp_length 895
loan_intent 25
loan_int_rate 3140
cb_person_default_on_file 15
.fillna() と集計関数などで欠損を補完cr_loan['loan_int_rate'].fillna((cr_loan['loan_int_rate'].mean()), inplace = True)
.drop() で該当行を削除indices = cr_loan[cr_loan['person_emp_length'].isnull()].index
cr_loan.drop(indices, inplace=True)
Pythonで学ぶクレジットリスクモデリング