# Handle Missing Data | Aced

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/4386/handle-missing-data
Source observed: 2026-11-04T22:02:43.806Z
Last checked: 2026-11-04T22:02:43.806+00:00
Indexed: 2026-11-05T06:34:04.585+00:00

---

# Handle Missing Data

**Difficulty:** Medium

We use this coding-interview practice question to teach several ways to handle missing values in a dataset. The interactive editor uses Python. Practice each option, then click **Reset** before starting the next one.

## Dataset

| student_id | name | gpa | credits_completed | year |
| --- | --- | --- | --- | --- |
| 1 | Alice | 3.5 | 15 | Freshman |
| 2 | Bob | 3.7 | NaN | Sophomore |
| 3 | Charlie | NaN | 45 | Junior |
| 4 | David | 3.2 | 50 | NaN |
| 5 | Eva | 3.9 | 70 | Senior |
| 6 | Frank | NaN | 20 | Freshman |
| 7 | Grace | 3.8 | 35 | Sophomore |
| 8 | Hannah | NaN | 35 | Junior |
| 9 | Ian | 3.4 | NaN | Senior |
| 10 | Jack | 3.1 | 60 | NaN |
| 11 | Kelly | 3.6 | 25 | Sophomore |
| 12 | Leo | NaN | NaN | Sophomore |

## Option 1: Drop all rows with missing data

The interviewer considers every row containing missing data unusable. Remove those rows. The expected result is:

| student_id | name | gpa | credits_completed | year |
| --- | --- | --- | --- | --- |
| 1 | Alice | 3.5 | 15 | Freshman |
| 5 | Eva | 3.9 | 70 | Senior |
| 7 | Grace | 3.8 | 35 | Sophomore |
| 11 | Kelly | 3.6 | 25 | Sophomore |

## Option 2: Drop all rows with missing GPA

Only rows whose `gpa` is missing are considered unusable. Remove those rows, while retaining other missing values:

| student_id | name | gpa | credits_completed | year |
| --- | --- | --- | --- | --- |
| 1 | Alice | 3.5 | 15 | Freshman |
| 2 | Bob | 3.7 | NaN | Sophomore |
| 4 | David | 3.2 | 50 | NaN |
| 5 | Eva | 3.9 | 70 | Senior |
| 7 | Grace | 3.8 | 35 | Sophomore |
| 9 | Ian | 3.4 | NaN | Senior |
| 10 | Jack | 3.1 | 60 | NaN |
| 11 | Kelly | 3.6 | 25 | Sophomore |

## Option 3: Replace missing values

Rather than removing rows:

- Fill missing `gpa` values with the mean GPA.
- Fill missing `credits_completed` values with the mean for the student's year. For example, use the average credits completed by sophomores for a sophomore.
- Fill missing `year` values with the most frequently occurring year.

Expected result:

| student_id | name | gpa | credits_completed | year |
| --- | --- | --- | --- | --- |
| 1 | Alice | 3.5 | 15 | Freshman |
| 2 | Bob | 3.7 | 30 | Sophomore |
| 3 | Charlie | 3.525 | 45 | Junior |
| 4 | David | 3.2 | 50 | Sophomore |
| 5 | Eva | 3.9 | 70 | Senior |
| 6 | Frank | 3.525 | 20 | Freshman |
| 7 | Grace | 3.8 | 35 | Sophomore |
| 8 | Hannah | 3.525 | 35 | Junior |
| 9 | Ian | 3.4 | 70 | Senior |
| 10 | Jack | 3.1 | 60 | Sophomore |
| 11 | Kelly | 3.6 | 25 | Sophomore |
| 12 | Leo | 3.525 | 30 | Sophomore |

The mean GPA is calculated as:

`(3.5 + 3.7 + 3.2 + 3.9 + 3.8 + 3.4 + 3.1 + 3.6) / 8 = 3.525`

The mean `credits_completed` for sophomores is:

`(35 + 25) / 2 = 30`

## Option 4: Interpolate

We do not interpolate this dataset. For more background, use our coding lesson on interpolation.

## Related question

- [How do you handle imbalanced data?](https://www.aced.io/questions/3531/handle-imbalanced-data)

## Access

- [All Questions](https://www.aced.io/questions)
- [Sign up to run code](https://www.aced.io/signup?src=lesson)

No community answers are currently available.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F4386%2Fhandle-missing-data&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F4386%2Fhandle-missing-data). Opening a form does not execute a tool.