Credit scoring: engineer a debt ratio feature
Scenario
You are a data scientist. Raw income and debt columns barely predict default. Credit risk analysts always reason in ratios, not absolutes.
Question
Make one useful clue called debt_to_income by dividing debt by income, while safely handling zero income.
Your task
- Divide monthly_debt by monthly_income
- Use a safe empty value when income is zero
- Stop one unusually large value from overpowering the model
Intermediate · Data Filtering & Record Counting — question 1 of 30
1. Choose your dataset
Pick an industry and a size. Your code and results change to match.
Credit scoring: engineer a debt ratio feature
Make one useful clue called debt_to_income by dividing debt by income, while safely handling zero income.
Your code cell is below. Press Check my answer to run the cell — the result appears as Out [1].
💡 Explain my whole code, line by line (hover any word in the editor for a tip)
🌈 In short — no coding words
Altogether: this script runs top to bottom, one line at a time, building up the answer step by step.
Dataset & schema
loan_applications
The tiny starter data. Bigger data scrolls.
Fields
| applicant_id | monthly_income | monthly_debt | defaulted |
|---|---|---|---|
| 1 | 24000 | 6000 | 0 |
| 2 | 0 | 3200 | 1 |
| 3 | 18500 | 14800 | 1 |
$ Press “Check my answer” — results appear here.Your next steps
Each item turns green when your answer includes it.
- Creates the ratio
- Guards divide-by-zero
- Finds the 99th percentile
- Caps the values