What you'll build
A loan eligibility screening system that reads a CSV of applicant data, evaluates each applicant against five bank rules, calculates maximum loan amounts and approval tiers, and outputs two CSV files: one with approved applicants and one with rejections + denial reasons.
Why this project matters
Every major fintech platformβfrom SouthBank India to M-Pesa Kenya to Jumiaβruns some form of eligibility logic before approving loans. This capstone mimics real production code. You'll learn:
- How to structure a rule engine using functions and conditionals
- File I/O and CSV processing with error handling
- Data validation and type safety (age as int, not string)
- How rule-based systems feed training data to ML classifiers
Interview angle: Loan eligibility logic is asked in senior Python/data roles. Building this from scratch is a strong portfolio project.
Prerequisites
You should have completed these lessons before starting:
- Variables & data types β int, str, bool, None
- Conditionals β if/elif/else logic
- Lists & dictionaries β storing and iterating data
- Functions β writing reusable functions with return values
- Error handling β try/except blocks
- File I/O & CSV β reading and writing CSVs
- Pandas (optional) β faster CSV processing
Bank policy & eligibility rules
Bonus: For approved applicants, calculate max loan as monthly_income Γ 24 and assign tier:
- Gold: credit_score β₯ 750
- Silver: credit_score 700β749
- Standard: credit_score 650β699
Data specification
The sample CSV contains 45 realistic applicants with these columns:
| Column | Type | Example | Notes |
|---|---|---|---|
applicant_id |
str | APP0042 | Unique identifier |
name |
str | Arjun Sharma | India/Kenya names |
age |
int | 28 | Cast from CSV string |
monthly_income |
int | 45000 | βΉ or KSh, no currency symbol |
credit_score |
int | 720 | 300β900 range |
existing_emi |
int | 12000 | Current monthly obligations |
employment_months |
int | 24 | Tenure at current job |
requested_amount |
int | 200000 | Loan requested by applicant |
pd.read_csv('applicants.csv') works.Step 1: Load & inspect data
Start by reading the CSV and inspecting a few rows. You can use either the csv module or pandas. Here's the pandas approach (simpler for tabular data):
Pro tip: Always cast numeric columns to int or float when reading CSVs. String "45000" is not the same as integer 45000 in comparisons.
Step 2: Build the rule engine
Create a function that checks all 5 rules and returns a tuple: (is_eligible, list_of_reasons). This makes testing and debugging easier.
Key insight: A function that returns both status AND reasons is production-grade code. It's testable, loggable, and auditable.
Step 3: Apply rules to every applicant
Loop through all 45 applicants, evaluate each one, and collect results into separate approved/rejected lists.
Now you have two clean lists. Let's enrich the approved list with loan tiers and max amounts before export.
Step 4: Calculate loan tier & maximum amount
For each approved applicant, assign a tier based on credit score and calculate the max they can borrow (24Γ monthly income).
Real-world note: In production, you'd also check if the requested amount is reasonable and might offer a lower tier-based cap.
Step 5: Export results to CSV
Write the approved and rejected lists to separate files for the business team to action.
Common pitfalls
if row['age'] > 21, Python compares strings ("28" > "21" is False alphabetically). Always cast: int(row['age']) or use pd.read_csv(..., dtype={'age': int}).existing_emi is missing, the EMI ratio calculation crashes. Always check: if pd.isna(applicant['existing_emi']): applicant['existing_emi'] = 0 before using it.if age < 21 to reject, not if age <= 21.Stretch goals (try these)
sys.argv or argparse to accept the CSV filename as a command-line argument instead of hard-coding it.schedule or cron to run the eligibility checker every night on new applicant CSVs and email results to the team.final_score = 0.7 * rules + 0.3 * ml_model.Interview Q&A for this project
if pd.isna(applicant['credit_score']): reasons.append("Credit score missing"). Or, treat missing as a hard fail (safest for lending). In production, you might pull it from a credit bureau API instead of rejecting outright.
max_loan_amount (24Γ monthly income) is what SouthBank is willing to lend. requested_amount is what the applicant asked for. If they request more than the max, they either get offered the max or are asked to lower their request. This is a business decision, not a hard reject.
Quick quiz
if age > 21?How this connects to AI & ML
Every modern credit-scoring system starts as a rule-based engine like yours, then evolves into machine learning. Here's the pipeline:
- Rules (now): Domain experts (loan officers) code up policy. Fast, auditable, low latency.
- Bootstrapping (month 1β3): Rules generate labels. Your dataset: 1000s of rule-labeled applicants.
- ML (month 4+): Train a model on rule-labeled data. The model learns hidden patterns (e.g., "age + income combo is better than income alone").
- Blending (month 6+): Run both rules and model. Weight them: 70% model, 30% rules (safety net).
- Full ML (month 12+): Retire rules, run pure ML. Continuously retrain on new applicant outcomes.
You're building the foundation every fintech company relies on.
Mini challenge
Add a 6th rule: "Requested loan amount must not exceed 50Γ the applicant's monthly_income." Implement it in the check_eligibility function without breaking the existing 5 rules. Test on one applicant manually and print the result.
Add another if check before the return statement. The check is: if applicant['requested_amount'] > applicant['monthly_income'] * 50: reasons.append("..."). Update the eligibility logic to require len(reasons) == 0.
Key takeaways
- Rule-based systems are production-grade when they return both a decision and reasons (transparent, auditable).
- Always cast CSV columns to the right type (int/float); string comparisons behave differently ("28" vs 28).
- Function signatures that return actionable data (not just True/False) are easier to test and integrate.
- Loan eligibility logic feeds training data to ML classifiers; you're building the first step of an AI pipeline.
- Export clean, well-named CSV files; downstream teams (agents, ops, risk) depend on your output column names.