Bird
Raised Fist0
Pandasdata~20 mins

Detecting missing values with isna() in Pandas - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Missing Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of isna() on a DataFrame column
What is the output of the following code snippet?
Pandas
import pandas as pd

df = pd.DataFrame({'A': [1, None, 3], 'B': [None, 2, 3]})
result = df['A'].isna()
print(result)
A
0     True
1    False
2     True
Name: A, dtype: bool
B
0    False
1     True
2    False
Name: A, dtype: bool
C
0    False
1    False
2    False
Name: A, dtype: bool
D
0     True
1     True
2     True
Name: A, dtype: bool
Attempts:
2 left
💡 Hint
Check which values in column 'A' are missing (None).
❓ data_output
intermediate
2:00remaining
Count missing values in DataFrame
What is the output of this code that counts missing values in each column?
Pandas
import pandas as pd

df = pd.DataFrame({'X': [1, 2, None, 4], 'Y': [None, None, 3, 4]})
missing_counts = df.isna().sum()
print(missing_counts)
A
X    0
Y    0
dtype: int64
B
X    2
Y    1
dtype: int64
C
X    1
Y    2
dtype: int64
D
X    1
Y    1
dtype: int64
Attempts:
2 left
💡 Hint
Count how many None values are in each column.
❓ visualization
advanced
3:00remaining
Visualizing missing values with isna()
Which option correctly creates a heatmap showing missing values in the DataFrame?
Pandas
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.DataFrame({'A': [1, None, 3], 'B': [None, 2, None], 'C': [1, 2, 3]})
sns.heatmap(____, cbar=False)
plt.show()
Adf.isna().sum()
Bdf.notna()
Cdf
Ddf.isna()
Attempts:
2 left
💡 Hint
Heatmap needs a boolean DataFrame showing missing values.
🔧 Debug
advanced
2:00remaining
Identify the error in missing value detection
What error will this code raise?
Pandas
import pandas as pd

df = pd.DataFrame({'A': [1, 2, 3]})
result = df.isna('A')
print(result)
ATypeError: isna() takes no arguments (1 given)
BKeyError: 'A'
CAttributeError: 'DataFrame' object has no attribute 'isna'
DNo error, prints a DataFrame of False values
Attempts:
2 left
💡 Hint
Check the method signature of isna().
🚀 Application
expert
3:00remaining
Filter rows with missing values in multiple columns
Given the DataFrame below, which code correctly filters rows where either column 'X' or 'Y' has missing values?
Pandas
import pandas as pd

df = pd.DataFrame({'X': [1, None, 3, None], 'Y': [None, 2, None, 4]})
Adf[df['X'].isna() | df['Y'].isna()]
Bdf[df.isna('X') | df.isna('Y')]
Cdf[df.isna()['X'] & df.isna()['Y']]
Ddf[df['X'].notna() | df['Y'].notna()]
Attempts:
2 left
💡 Hint
Use isna() on each column separately and combine with | for OR.

Practice

(1/5)
1. What does the pandas.DataFrame.isna() function do?
easy
A. It converts all values to strings.
B. It fills missing values with zeros.
C. It removes rows with missing values.
D. It shows which values in the DataFrame are missing (NaN).

Solution

  1. Step 1: Understand the purpose of isna()

    The isna() function checks each cell in a DataFrame and marks True if the value is missing (NaN), otherwise False.
  2. Step 2: Compare options with function behavior

    Only It shows which values in the DataFrame are missing (NaN). correctly describes this behavior. Options B, C, and D describe other functions or actions.
  3. Final Answer:

    It shows which values in the DataFrame are missing (NaN). -> Option D
  4. Quick Check:

    isna() = marks missing values True [OK]
Hint: Remember: isna() marks missing spots True [OK]
Common Mistakes:
  • Confusing isna() with fillna()
  • Thinking isna() removes data
  • Assuming isna() changes data types
2. Which of the following is the correct syntax to check missing values in a DataFrame named df?
easy
A. isna(df)
B. df.isna
C. df.isna()
D. df.isna[]

Solution

  1. Step 1: Recall method call syntax in pandas

    Methods like isna() must be called with parentheses on the DataFrame object, so df.isna() is correct.
  2. Step 2: Evaluate each option

    df.isna() uses correct syntax. df.isna misses parentheses, so it returns the method object, not the result. isna(df) is incorrect because isna is a method, not a standalone function. df.isna[] uses invalid bracket syntax.
  3. Final Answer:

    df.isna() -> Option C
  4. Quick Check:

    Method call needs parentheses () [OK]
Hint: Use parentheses to call isna(): df.isna() [OK]
Common Mistakes:
  • Forgetting parentheses after isna
  • Trying to call isna as a standalone function
  • Using brackets instead of parentheses
3. Given the DataFrame:
import pandas as pd
data = {'A': [1, None, 3], 'B': [4, 5, None]}
df = pd.DataFrame(data)
print(df.isna())

What is the output?
medium
A. A B 0 False False 1 True False 2 False True
B. A B 0 True False 1 False True 2 False False
C. A B 0 False True 1 False False 2 True False
D. A B 0 False False 1 False True 2 True False

Solution

  1. Step 1: Identify missing values in each column

    Column 'A' has None at index 1, so True there. Column 'B' has None at index 2, so True there. All other values are present (False).
  2. Step 2: Match the True/False pattern to output

    A B 0 False False 1 True False 2 False True matches the pattern: index 1 in 'A' is True, index 2 in 'B' is True, others False.
  3. Final Answer:

    A B 0 False False 1 True False 2 False True -> Option A
  4. Quick Check:

    None values marked True by isna() [OK]
Hint: Look for None positions; isna() marks them True [OK]
Common Mistakes:
  • Mixing row and column positions
  • Confusing True and False values
  • Assuming isna() replaces values
4. You run this code:
import pandas as pd
data = {'X': [10, 20, None], 'Y': [None, 40, 50]}
df = pd.DataFrame(data)
missing = df.isna

Why does missing.sum() cause an error?
medium
A. Because missing is a DataFrame, not a function.
B. Because isna is not called with parentheses when assigned.
C. Because isna() does not exist in pandas.
D. Because df is not defined.

Solution

  1. Step 1: Understand method assignment without parentheses

    Assigning missing = df.isna stores the method itself, not the result. To get the result, you must call it with parentheses.
  2. Step 2: Explain why missing.sum() causes error

    Assigning missing = df.isna stores the method object, not the DataFrame result. Method objects do not have a .sum() attribute--only DataFrames do. Thus, missing.sum() raises AttributeError.
  3. Final Answer:

    Because isna is not called with parentheses when assigned. -> Option B
  4. Quick Check:

    Assign method with () to get result [OK]
Hint: Assign with parentheses to get result, not method [OK]
Common Mistakes:
  • Assigning method without parentheses and expecting result
  • Confusing method object with method call
  • Assuming isna() is not a pandas method
5. You have a DataFrame df with columns 'Age' and 'Salary'. You want to count how many missing values are in each column using isna(). Which code correctly does this?
hard
A. df.isna().sum()
B. df.isna.sum()
C. df.sum().isna()
D. df.isna().count()

Solution

  1. Step 1: Use isna() to mark missing values

    The isna() method returns True for missing values and False otherwise.
  2. Step 2: Sum True values per column to count missing

    Since True is treated as 1 and False as 0, summing over rows counts missing values per column. So df.isna().sum() gives the count per column.
  3. Final Answer:

    df.isna().sum() -> Option A
  4. Quick Check:

    Sum True from isna() to count missing [OK]
Hint: Sum isna() results to count missing per column [OK]
Common Mistakes:
  • Forgetting parentheses after isna
  • Using count() which counts all rows, not missing
  • Applying sum() before isna()
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard