AnalystPath

Suggest Study Partners

PandasHardSenior level~10 min

Problem

A study app logs which practice problems each student solved on each day, and tracks existing study-partner links.

DataFrame `solved` (from `solved.csv`):

```text
+------------+------+
| Column | Type |
+------------+------+
| student_id | int |
| problem_id | int |
| solve_date | date |
+------------+------+
Each row means the student solved the problem on the given date.
```

DataFrame `partners` (from `partners.csv`):

```text
+-----------+------+
| Column | Type |
+-----------+------+
| student_x | int |
| student_y | int |
+-----------+------+
(student_x, student_y) is the primary key. Each row means the two students are already study partners.
```

Suggest student `a` to student `b` when both hold:
- `a` and `b` are not already study partners (in either direction).
- `a` and `b` solved the same **three or more distinct problems on the same day**.

Suggestions are bidirectional: if `a` is suggested to `b`, then `b` must also be suggested to `a`. The result must contain no duplicate rows.

Return a DataFrame with columns `student_id` and `suggested_id`, in any order.

Input data

Example rows — the live problem includes the full dataset.

solved
student_idproblem_idsolve_date
1102021-03-15
1112021-03-15
1122021-03-15
2102021-03-15
2112021-03-15
partners
student_xstudent_y
12

Expected output

Your answer should return 6 rows with the columns student_id, suggested_id.

Starter code (Pandas (Python))

import pandas as pd

def suggest_study_partners(solved, partners) -> pd.DataFrame:
    # Your code here
    return solved

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