Above-Average Campuses
Problem
You are given a DataFrame `menu_item` with columns `item_id`, `campus`, and `price_cents`. `item_id` is unique. Each row is one cafeteria menu item sold on a `campus`, priced in cents.
A campus is considered expensive when its average item price is strictly greater than the average item price across all campuses combined (the mean over every individual item). Return the `campus` names of the expensive campuses in a single column `campus`, sorted alphabetically ascending.
Input data
Example rows — the live problem includes the full dataset.
| item_id | campus | price_cents |
|---|---|---|
| 1 | North | 800 |
| 2 | North | 900 |
| 3 | South | 400 |
| 4 | South | 500 |
| 5 | West | 700 |
Expected output
Your answer should return 2 rows with the columns campus.
Starter code (Pandas (Python))
import pandas as pd
def above_average_campuses(menu_item) -> pd.DataFrame:
# Your code here
return menu_itemSolve 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