AnalystPath

Monthly Ad Performance by Region

PandasMediumMid level~10 min

Problem

You are given a DataFrame `clicks` loaded from `clicks.csv` with columns `click_id`, `region`, `outcome`, `spend`, and `click_day`. `outcome` is either `'converted'` or `'bounced'`, and `spend` is the cost of the click in cents.

For each month and region, report the total number of clicks and their total spend, plus the number of **converted** clicks and their total spend. Format the month as `YYYY-MM`. Return columns in this exact order: `month`, `region`, `total_clicks`, `converted_clicks`, `total_spend`, `converted_spend`.

Input data

Example rows — the live problem includes the full dataset.

clicks
click_idregionoutcomespendclick_day
1EUconverted302024-01-05
2EUbounced202024-01-20
3USconverted402024-01-08

Expected output

Your answer should return 2 rows with the columns month, region, total_clicks, converted_clicks, total_spend, converted_spend.

Starter code (Pandas (Python))

import pandas as pd

def ad_performance(clicks) -> pd.DataFrame:
    # Your code here
    return clicks

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