AnalystPath

Shrinking Insurance Policies

PandasMediumMid level~10 min

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.

policy_history
change_idholder_idchange_datechange_kindtier_namemonthly_premium
11002024-01-01openplatinum80.0
21002024-02-15reducegold50.0
31002024-03-20reducesilver30.0
42002024-01-05opengold60.0
52002024-02-10reducesilver35.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_history

Solve 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

Related Pandas questions