AnalystPath

Driver Churn Year-over-Year

PandasHardSenior levelLyft~15 min

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_iddriver_idtrip_date
11012022-05-01
21022022-06-01
31032022-07-01
41012023-01-01
51042023-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 trips

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