AnalystPath

Average Reviewer Tenure per Grant

PandasEasyJunior level~10 min

Problem

DataFrame: `assignment` (`assignment.csv`)

```text
+-------------+------+
| Column | Type |
+-------------+------+
| grant_id | int |
| reviewer_id | int |
+-------------+------+
Each row assigns one reviewer to one grant. (grant_id, reviewer_id) is unique.
```

DataFrame: `reviewer` (`reviewer.csv`)

```text
+--------------+--------+
| Column | Type |
+--------------+--------+
| reviewer_id | int |
| full_name | object |
| tenure_years | int |
+--------------+--------+
reviewer_id uniquely identifies each reviewer.
```

Write a function that returns, for every grant, the **average tenure** (in years) of the reviewers assigned to it, rounded to 2 decimal places. Name the column `avg_tenure`.

Return the result in any order.

**Example**

Input — `assignment`:

```text
grant_id reviewer_id
1 1
1 2
1 3
2 1
2 4
```

Input — `reviewer`:

```text
reviewer_id full_name tenure_years
1 Mara Voss 3
2 Theo Lin 2
3 Sana Roy 1
4 Owen Park 2
```

Output:

```text
grant_id avg_tenure
1 2.0
2 2.5
```

Grant 1's reviewers have tenures 3, 2, 1 (average 2.0); grant 2's are 3 and 2 (average 2.5).

Input data

Example rows — the live problem includes the full dataset.

assignment
grant_idreviewer_id
11
12
13
21
24
reviewer
reviewer_idfull_nametenure_years
1Mara Voss3
2Theo Lin2
3Sana Roy1
4Owen Park2

Expected output

Your answer should return 2 rows with the columns grant_id, avg_tenure.

Starter code (Pandas (Python))

import pandas as pd

def avg_tenure_per_grant(assignment: pd.DataFrame, reviewer: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return assignment

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