AnalystPath

Members Active in Two Quarters

PandasEasyJunior level~10 min

Problem

A gym tracks every class booking. Each booking links a member to a class, and each class has a credit cost.

`members` columns: `member_id`, `member_name`, `home_city`.
`classes` columns: `class_id`, `class_title`, `cost`.
`bookings` columns: `booking_id`, `member_id`, `class_id`, `booked_on`, `seats`.

Find the members who spent **at least 50 credits in Q1 2023 (Jan-Mar) AND at least 50 credits in Q2 2023 (Apr-Jun)**. The credits for a booking are `seats * cost`.

Return `member_id` and `member_name`. Order does not matter.

Input data

Example rows — the live problem includes the full dataset.

members
member_idmember_namehome_city
1PriyaAustin
2DiegoLima
3HanaOsaka
classes
class_idclass_titlecost
10Spin150
20Yoga5
30Boxing22
40Sauna1
bookings
booking_idmember_idclass_idbooked_onseats
11102023-02-101
21202023-04-011
31302023-04-083
42102023-02-152
52402023-04-0110

Expected output

Your answer should return 1 row with the columns member_id, member_name.

Starter code (Pandas (Python))

import pandas as pd

def members_active_in_two_quarters(members, classes, bookings) -> pd.DataFrame:
    # Your code here
    return members

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