Skip to main content
Back to problems
#2883
Easy pandas

Drop missing data

64.5% acceptance
Mar 2, 2026
101
7
DataFrame students +-------------+--------+ | Column Name | Type | +-------------+--------+ | student_id | int | | name | object | | age | int | +-------------+--------+ There are some rows having missing values in the name column. Write a solution to remove the rows with missing values. The result format is in the following example.

Solution

Pandas
Time O(1)
Space O(1)
LeetCode
solution.pandas
# DataFrame students
# +-------------+--------+
# | Column Name | Type   |
# +-------------+--------+
# | student_id  | int    |
# | name        | object |
# | age         | int    |
# +-------------+--------+
# There are some rows having missing values in the name column.

# Write a solution to remove the rows with missing values.

# The result format is in the following example.


# Example 1:

# Input:
# +------------+---------+-----+
# | student_id | name    | age |
# +------------+---------+-----+
# | 32         | Piper   | 5   |
# | 217        | None    | 19  |
# | 779        | Georgia | 20  |
# | 849        | Willow  | 14  |
# +------------+---------+-----+
# Output:
# +------------+---------+-----+
# | student_id | name    | age |
# +------------+---------+-----+
# | 32         | Piper   | 5   |
# | 779        | Georgia | 20  |
# | 849        | Willow  | 14  |
# +------------+---------+-----+
# Explanation:
# Student with id 217 havs empty value in the name column, so it will be removed.

import pandas as pd


def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:
  return students.dropna(subset=["name"])