AnalystPath

Saturday Sales by Loyalty Tier

PandasMediumMid level~10 min

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.

orders
shopper_idorder_daycents_paid
112024-09-071126
152024-09-147473
172024-09-212414
122024-09-289692
82024-09-285117
shoppers
shopper_idtier
11Gold
15Silver
17Bronze
12Silver
8Gold

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 orders

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