Monthly Ad Performance by Region
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.
| click_id | region | outcome | spend | click_day |
|---|---|---|---|---|
| 1 | EU | converted | 30 | 2024-01-05 |
| 2 | EU | bounced | 20 | 2024-01-20 |
| 3 | US | converted | 40 | 2024-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 clicksSolve 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