Saturday Sales by Loyalty Tier
Problem
You are given two DataFrames. `orders` (CSV `orders.csv`, one row per order) has columns shopper_id, order_day, and cents_paid; `shoppers` (CSV `shoppers.csv`) has columns shopper_id and tier. A farmers' market opens every Saturday; in September 2024 those Saturdays were the 7th, 14th, 21st, and 28th (week 1 is the first Saturday and so on). Report the total spend by `Gold` and `Silver` shoppers on each of those four Saturdays. Every combination of week and the two tiers must appear, with a total of 0 when there were no qualifying orders that day. Output columns: `week_no`, `tier`, and `total_cents`, ordered by `week_no` then `tier`.
Input data
Example rows — the live problem includes the full dataset.
| shopper_id | order_day | cents_paid |
|---|---|---|
| 11 | 2024-09-07 | 1126 |
| 15 | 2024-09-14 | 7473 |
| 17 | 2024-09-21 | 2414 |
| 12 | 2024-09-28 | 9692 |
| 8 | 2024-09-28 | 5117 |
| shopper_id | tier |
|---|---|
| 11 | Gold |
| 15 | Silver |
| 17 | Bronze |
| 12 | Silver |
| 8 | Gold |
Expected output
Your answer should return 8 rows with the columns week_no, tier, total_cents.
Starter code (Pandas (Python))
import pandas as pd
def saturday_sales_by_loyalty_tier(orders, shoppers) -> pd.DataFrame:
# Your code here
return ordersSolve 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