AnalystPath

Members Lifting Heavier Over Time

PandasMediumMid level~10 min

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.

lift_log
member_idexerciseweight_kglogged_on
501Squat802024-03-02
501Squat952024-03-30
501Bench602024-03-02
501Bench552024-03-30
502Squat1002024-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_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