Drop Missing Data - Problem

You are given a DataFrame called students with the following schema:

Column NameType
student_idint
nameobject
ageint

Some rows in the DataFrame have missing values in the name column (represented as null or NaN).

Write a solution to remove all rows that contain missing values in the name column and return the cleaned DataFrame.

Input & Output

Example 1 — Basic Missing Data
$ Input: students = [{"student_id": 1, "name": "Alice", "age": 20}, {"student_id": 2, "name": null, "age": 21}]
Output: [{"student_id": 1, "name": "Alice", "age": 20}]
💡 Note: Row with student_id=2 has missing name (null), so it's removed. Only Alice's record remains.
Example 2 — Multiple Missing Names
$ Input: students = [{"student_id": 1, "name": "Bob", "age": 22}, {"student_id": 2, "name": null, "age": 23}, {"student_id": 3, "name": "Charlie", "age": 24}]
Output: [{"student_id": 1, "name": "Bob", "age": 22}, {"student_id": 3, "name": "Charlie", "age": 24}]
💡 Note: Student with ID 2 has missing name, so removed. Bob and Charlie remain.
Example 3 — No Missing Data
$ Input: students = [{"student_id": 1, "name": "David", "age": 25}, {"student_id": 2, "name": "Eve", "age": 26}]
Output: [{"student_id": 1, "name": "David", "age": 25}, {"student_id": 2, "name": "Eve", "age": 26}]
💡 Note: All students have valid names, so no rows are removed.

Constraints

  • 1 ≤ students.length ≤ 1000
  • Each row contains student_id (int), name (string or null), age (int)
  • Missing values in name column are represented as null

Visualization

Tap to expand
Drop Missing Data - Pandas dropna() INPUT DataFrame student_id name age 1 Alice 20 OK 2 null 21 X Valid row Row with null students = [ {"id":1,"name":"Alice"}, {"id":2,"name":null} ] ALGORITHM STEPS 1 Identify Column Target: 'name' column 2 Scan for NaN Check each row for null 3 Apply dropna() subset=['name'] 4 Return Result Cleaned DataFrame df.dropna( subset=['name'], inplace=True) 2 rows --> 1 row FINAL RESULT student_id name age 1 Alice 20 Row with null removed Output: [{"student_id": 1, "name": "Alice", "age": 20}] Cleaned DataFrame 1 row remaining (OK) Rows removed: 1 Rows kept: 1 Key Insight: The dropna() method with subset=['name'] removes ONLY rows where the 'name' column has missing values. Other columns are not checked. Use inplace=True to modify the original DataFrame, or assign to a new variable. df_clean = df.dropna(subset=['name']) # Creates new DataFrame without null names TutorialsPoint - Drop Missing Data | Pandas dropna() Method
Asked in
Meta 15 Netflix 12
33.8K Views
High Frequency
~5 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen