Driver Churn Year-over-Year
Problem
**[Asked at Lyft and Uber]**
For each year (after the first), count the **number of drivers who churned** —
drivers who were active in the previous year but not in the current year.
Return `year` and `churned`, ordered by year.
Input data
Example rows — the live problem includes the full dataset.
trips
| trip_id | driver_id | trip_date |
|---|---|---|
| 1 | 101 | 2022-05-01 |
| 2 | 102 | 2022-06-01 |
| 3 | 103 | 2022-07-01 |
| 4 | 101 | 2023-01-01 |
| 5 | 104 | 2023-02-01 |
Expected output
Your answer should return 2 rows with the columns year, churned.
Starter code (Pandas (Python))
import pandas as pd
def driver_churn(trips: pd.DataFrame) -> pd.DataFrame:
# Your code here
return tripsSolve 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