Members With a Quick Repeat Borrow
Problem
You are given a DataFrame `borrow_log` with columns `member_id`, `title`, `borrowed_on` (a date string), and `fee_cents`. There is no unique key; a member may borrow several titles, and the same member can appear on many dates. Each row records a single borrow event.
A member is *engaged* if they have two consecutive (in time) borrow events whose dates are 7 days apart or less. Report the `member_id` of every engaged member, each id once. The result may be returned in any order.
Input data
Example rows — the live problem includes the full dataset.
| member_id | title | borrowed_on | fee_cents |
|---|---|---|---|
| 5 | Tide Tables | 2022-04-01 | 0 |
| 5 | Marsh Birds | 2022-04-05 | 0 |
| 6 | Clay Sculpting | 2022-04-01 | 50 |
| 6 | Glaze Recipes | 2022-04-20 | 0 |
| 7 | Solo Read | 2022-04-10 | 0 |
Expected output
Your answer should return 1 row with the columns member_id.
Starter code (Pandas (Python))
import pandas as pd
def members_with_a_quick_repeat_borrow(borrow_log) -> pd.DataFrame:
# Your code here
return borrow_logSolve 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