Challenge - 5 Problems
Missing Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Counting missing values in a DataFrame column
What is the output of this code that counts missing values in the 'Age' column?
Pandas
import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie', 'David'], 'Age': [25, None, 30, None]} df = pd.DataFrame(data) missing_count = df['Age'].isna().sum() print(missing_count)
Attempts:
2 left
💡 Hint
Use isna() to find missing values and sum() to count them.
✗ Incorrect
The 'Age' column has two missing values (None). isna() marks them as True, sum() counts True as 1 each, so the result is 2.
❓ data_output
intermediate2:00remaining
Count missing values per column in a DataFrame
What is the output of this code that counts missing values for each column?
Pandas
import pandas as pd data = {'A': [1, None, 3], 'B': [None, None, 6], 'C': [7, 8, 9]} df = pd.DataFrame(data) missing_per_column = df.isna().sum() print(missing_per_column)
Attempts:
2 left
💡 Hint
Use isna() on the whole DataFrame and sum() to count per column.
✗ Incorrect
Column 'A' has 1 missing, 'B' has 2 missing, 'C' has none. So the output shows counts per column.
❓ visualization
advanced2:30remaining
Visualizing missing values count per column
Which option produces a bar chart showing the count of missing values per column?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = {'X': [1, None, 3, None], 'Y': [None, 2, None, 4], 'Z': [5, 6, 7, 8]} df = pd.DataFrame(data) missing_counts = df.isna().sum() # Which code below plots the bar chart correctly?
Attempts:
2 left
💡 Hint
Plot the Series of missing counts, not the whole DataFrame.
✗ Incorrect
missing_counts is a Series with counts per column. Using plot(kind='bar') on it creates the correct bar chart.
🧠 Conceptual
advanced1:30remaining
Understanding the difference between isna() and notna()
If df is a DataFrame, what does df.notna().sum() return?
Attempts:
2 left
💡 Hint
notna() is the opposite of isna().
✗ Incorrect
notna() returns True for non-missing values. sum() counts True as 1, so it counts non-missing values per column.
🔧 Debug
expert2:00remaining
Why does this code give an error when counting missing values?
What error does this code raise and why?
import pandas as pd
data = {'A': [1, 2, None], 'B': [None, 4, 5]}
df = pd.DataFrame(data)
missing = df.isna.sum()
print(missing)
Attempts:
2 left
💡 Hint
Check if isna is called as a method.
✗ Incorrect
isna is a method and must be called with parentheses: isna(). Without parentheses, isna is a method object, which has no sum attribute.