Remove rows that contain a missing value from a tabular dataset. By hand, scan parallel lists for None entries and collect only the names whose score is present. With pandas, DataFrame.dropna() filters out every row with at least one NaN in a single call.

By hand

With pandas

Build a DataFrame from the parallel lists — pandas infers float64 for the numeric column, converting None to NaN. df.dropna() returns a new DataFrame without any NaN rows. The snapshot shows the shape before and after so the drop count is immediately visible.

naive.py
names  = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
scores = [82, None, 91, None, 74]
kept = []
for i in range(len(names)):
    if scores[i] is not None:
        kept.append(names[i])
print('RESULT:', kept)
library.py
import pandas as pd
from dalib.display import set_display
set_display()

names  = ['Alice', 'Bob', 'Carol', 'Dave', 'Eve']
scores = [82, None, 91, None, 74]
df = pd.DataFrame({'name': names, 'score': scores})
clean = df.dropna()
result = clean['name'].tolist()
print('columns:', df.columns.tolist())
print('shape before:', df.shape)
print('shape after:', clean.shape)
print('RESULT:', result)
columns: ['name', 'score']
shape before: (5, 2)
shape after: (3, 2)
RESULT: ['Alice', 'Carol', 'Eve']

Implementation notes

  • dropna() drops any row that has at least one NaN by default (how='any'). Pass how='all' to drop only rows where every cell is missing.
  • subset=['score'] limits the check to the score column, leaving rows with missing values in other columns intact.
  • The returned DataFrame keeps its original index labels — use .reset_index (drop=True) after if you need a clean 0-based index.
  • Cross-reference: detect-missing (this chapter) for identifying which positions are missing before deciding whether to drop or fill.