Skip to content

2883. Drop Missing Data

DataFrame students

Column NameType
student_idint
nameobject
ageint

Instructions

  • 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

Input:

student_idnameage
32Piper5
217None19
779Georgia20
849Willow14

Output:

student_idnameage
32Piper5
779Georgia20
849Willow14

Explanation:

Student with id 217 havs empty value in the name column, so it will be removed.

Submissions

python
import pandas as pd

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

Explanation

Python (Pandas)
Submitted by @noeyislearning
  • import pandas as pd: Import the pandas library to work with DataFrames.
  • def dropMissingData(students: pd.DataFrame) -> pd.DataFrame:: Define a function called dropMissingData that takes a DataFrame students as input and returns a DataFrame.
  • return students.dropna(subset=['name']): Remove the rows with missing values in the name column.