AnalystPath

Net Product Launches Year-over-Year

PandasMediumMid level~15 min

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_idlaunch_yeardiscontinue_year
120202022
22020
320212023
42021
52022

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 products

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