Hanukkah of Data 5784 - Day 6 The Bargain Hunter

:: programming, python, puzzle

The Task

We’re given the clue that the person is a bargain hunter, along with the comment “I like to tease her that Noah actually loses money whenever she comes in the store”. I took the latter to mean the unit_price of the order_item was below the wholesale_cost of the product.

The Solution

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import pandas as pd

customers   = pd.read_csv('noahs-customers.csv')
orders      = pd.read_csv('noahs-orders.csv')
order_items = pd.read_csv('noahs-orders_items.csv')
products    = pd.read_csv('noahs-products.csv')
data        = customers.merge(orders).merge(order_items).merge(products)

below_cost = data['unit_price'] < data['wholesale_cost']
grouped    = data[below_cost][['customerid','phone','unit_price']].groupby(['customerid', 'phone']).count()

assert grouped[grouped['unit_price'] == grouped['unit_price'].max()].reset_index().iloc[0]['phone'] == '585-838-9161'