Tuition Collected by Each Tutor
Problem
You are given three DataFrames. `Tutor` has columns `tutor_id` and `tutor_name`. `Student` has columns `student_id` and `tutor_id`. `Payment` has columns `payment_id`, `student_id`, and `amount`. Return a DataFrame with columns `tutor_id`, `tutor_name`, and `collected`, where `collected` is the sum of all payment amounts made by that tutor's students. A tutor with no students, or whose students made no payments, has a `collected` value of 0. Row order does not matter.
Input data
Example rows — the live problem includes the full dataset.
| tutor_id | tutor_name |
|---|---|
| 11 | Dana |
| 12 | Omar |
| 13 | Priya |
| student_id | tutor_id |
|---|---|
| 101 | 11 |
| 102 | 11 |
| 103 | 12 |
| payment_id | student_id | amount |
|---|---|---|
| 1 | 102 | 320 |
| 2 | 101 | 145 |
| 3 | 103 | 410 |
| 4 | 103 | 260 |
Expected output
Your answer should return 3 rows with the columns tutor_id, tutor_name, collected.
Starter code (Pandas (Python))
import pandas as pd
def tuition_per_tutor(Tutor, Student, Payment) -> pd.DataFrame:
# Your code here
return TutorSolve 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