Members Lifting Heavier Over Time
Problem
You are given one DataFrame `lift_log` with columns `member_id`, `exercise`, `weight_kg`, and `logged_on` (a date string `YYYY-MM-DD`), one row per logged set.
Find each (member, exercise) pairing where the member logged the same exercise on **at least two different dates** and the weight on their **latest** date is strictly greater than the weight on their **first** date. Only the earliest and most recent entries matter — anything in between is ignored.
Return columns `member_id`, `exercise`, `first_weight` (the earliest weight), and `latest_weight` (the most recent weight), ordered by `member_id` then `exercise`.
Input data
Example rows — the live problem includes the full dataset.
| member_id | exercise | weight_kg | logged_on |
|---|---|---|---|
| 501 | Squat | 80 | 2024-03-02 |
| 501 | Squat | 95 | 2024-03-30 |
| 501 | Bench | 60 | 2024-03-02 |
| 501 | Bench | 55 | 2024-03-30 |
| 502 | Squat | 100 | 2024-03-05 |
Expected output
Your answer should return 3 rows with the columns member_id, exercise, first_weight, latest_weight.
Starter code (Pandas (Python))
import pandas as pd
def members_lifting_heavier(lift_log) -> pd.DataFrame:
# Your code here
return lift_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