Convert age to numbers (bad text becomes NaN). Ages below 0 or above 100 are typing mistakes: make them missing too. Then fill every missing age with the median of the valid ages.
Store the final age column as integers in result.
import pandas as pd
import numpy as np
customers = pd.DataFrame({
"cust_id": [101, 102, 103, 104, 105, 105, 106, 107, 108, 109, 110, 111, 112],
"name": ["Asha Rao", "ravi kumar", " Kiran Shah ", "MEENA IYER", "Om Prakash", "Om Prakash", "Farah Khan",
"Neha Joshi", None, "Arjun Mehta", "Sneha Pillai", "Vikram Das", "asha rao"],
"email": ["asha@mail.com", "RAVI@MAIL.COM", "kiran@mail", "meena@mail.com", "om@mail.com", "om@mail.com",
" farah@mail.com", "neha@mail.com", "unknown", "arjun@mail.com", "", "vikram@mail.com", "ASHA@mail.com "],
"phone": ["98765 43210", "+91-9876543211", "9876543212", "987654321", "9876543214", "9876543214", "09876543215",
"NA", "9876543217", "98765-43218", "9876543219", "-", "98765 43210"],
"city": ["Pune", "pune", "Mumbai", "Bombay", "Delhi", "Delhi", "New Delhi", "Bengaluru", "Bangalore", "Chennai",
"chennai ", "Pune", "PUNE"],
"age": ["28", "35", "41", "-1", "29", "29", "230", "33", "NA", "45", "38", "27", "28"],
"monthly_income": [45000, 62000, 88000, 51000, 39000, 39000, 120000, 0, 57000, 95000, np.nan, 43000, 45000],
"plan": ["Gold", "gold", "Silver ", "GOLD", "Basic", "Basic", "silver", "Gold", "basic", "Silver", "Basic", "gold", "Gold"],
"signup": ["2025-01-05", "2025-01-12", "2025-02-03", "2025-02-14", "2025-02-20", "2025-02-20", "2025-03-01",
"not given", "2025-03-09", "2025-03-15", "2025-03-22", "2025-04-02", "2025-04-10"],
})Store your final answer in a variable named result.
Each hint gives a little more help. Try on your own first.
Run your code to see the output here.