AnalystPath

Members With a Quick Repeat Borrow

PandasMediumMid level~10 min

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.

borrow_log
member_idtitleborrowed_onfee_cents
5Tide Tables2022-04-010
5Marsh Birds2022-04-050
6Clay Sculpting2022-04-0150
6Glaze Recipes2022-04-200
7Solo Read2022-04-100

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_log

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