Shrinking Insurance Policies
Problem
You are given one DataFrame `policy_history` (loaded from `policy_history.csv`), a full history of policy changes with columns `change_id`, `holder_id`, `change_date`, `change_kind` ('open', 'upgrade', 'reduce', or 'close'), `tier_name`, and `monthly_premium` in force after that change. Flag the shrinking policies: holders whose policy is still in force (their most recent change is not a 'close'), who have reduced coverage at least once (at least one 'reduce' change), whose current monthly premium is below half of the highest premium they ever paid, and who have been a holder for at least 60 days (from their first to their latest change). Return a DataFrame with the `holder_id` of each flagged holder. Order by tenure in days descending, then by `holder_id` ascending.
Input data
Example rows — the live problem includes the full dataset.
| change_id | holder_id | change_date | change_kind | tier_name | monthly_premium |
|---|---|---|---|---|---|
| 1 | 100 | 2024-01-01 | open | platinum | 80.0 |
| 2 | 100 | 2024-02-15 | reduce | gold | 50.0 |
| 3 | 100 | 2024-03-20 | reduce | silver | 30.0 |
| 4 | 200 | 2024-01-05 | open | gold | 60.0 |
| 5 | 200 | 2024-02-10 | reduce | silver | 35.0 |
Expected output
Your answer should return 2 rows with the columns holder_id.
Starter code (Pandas (Python))
import pandas as pd
def find_shrinking_policies(policy_history) -> pd.DataFrame:
# Your code here
return policy_historySolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock