以 Python 進行信用風險建模
Michael Crabtree
Data Scientist, Ford Motor Company
''| 遺漏值類型 | 可能結果 |
|---|---|
| 數值欄中的 NULL | Error |
| 字串欄中的 NULL | Error |
| 遺漏值 | 解讀 | 動作 |
|---|---|---|
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 進行信用風險建模