Net Product Launches Year-over-Year
Problem
**[Asked at Automotive companies]**
Each product has a `launch_year` and (optionally) a `discontinue_year`.
For each year of activity, compute:
- `launches`: products launched that year
- `discontinued`: products discontinued that year
- `net`: launches - discontinued
Return `year`, `launches`, `discontinued`, `net`, ordered by year.
Input data
Example rows — the live problem includes the full dataset.
products
| product_id | launch_year | discontinue_year |
|---|---|---|
| 1 | 2020 | 2022 |
| 2 | 2020 | |
| 3 | 2021 | 2023 |
| 4 | 2021 | |
| 5 | 2022 |
Expected output
Your answer should return 4 rows with the columns year, launches, discontinued, net.
Starter code (Pandas (Python))
import pandas as pd
def net_launches(products: pd.DataFrame) -> pd.DataFrame:
# Your code here
return productsSolve 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