Bird
Raised Fist0
Pandasdata~20 mins

Counting missing values 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
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)
A2
B0
C4
DNone
Attempts:
2 left
💡 Hint
Use isna() to find missing values and sum() to count them.
❓ data_output
intermediate
2: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)
A
A    2
B    1
C    0
dtype: int64
B
A    0
B    0
C    0
dtype: int64
C
A    1
B    2
C    0
dtype: int64
D
A    1
B    1
C    1
dtype: int64
Attempts:
2 left
💡 Hint
Use isna() on the whole DataFrame and sum() to count per column.
❓ visualization
advanced
2: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?
A
df.plot(kind='bar')
plt.show()
B
missing_counts.plot(kind='bar')
plt.show()
C
missing_counts.plot.bar()
plt.show()
D
df.isna().plot(kind='bar')
plt.show()
Attempts:
2 left
💡 Hint
Plot the Series of missing counts, not the whole DataFrame.
🧠 Conceptual
advanced
1:30remaining
Understanding the difference between isna() and notna()
If df is a DataFrame, what does df.notna().sum() return?
ABoolean DataFrame showing missing values
BTotal number of rows in the DataFrame
CCount of missing values per column
DCount of non-missing values per column
Attempts:
2 left
💡 Hint
notna() is the opposite of isna().
🔧 Debug
expert
2: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)
AAttributeError: 'method' object has no attribute 'sum' because isna is missing parentheses
BTypeError: unsupported operand type(s) for +: 'method' and 'method' because sum is called incorrectly
CKeyError because 'isna' is not a column
DNo error, prints the count of missing values
Attempts:
2 left
💡 Hint
Check if isna is called as a method.

Practice

(1/5)
1. What does the pandas method df.isna().sum() do when applied to a DataFrame df?
easy
A. Counts the total number of rows in the DataFrame
B. Counts the number of missing values in each column of the DataFrame
C. Replaces missing values with zero in the DataFrame
D. Returns the data types of each column in the DataFrame

Solution

  1. Step 1: Understand df.isna()

    This method returns a DataFrame of the same shape as df with True where values are missing and False otherwise.
  2. Step 2: Apply .sum() on the boolean DataFrame

    Summing True values (which count as 1) per column gives the count of missing values in each column.
  3. Final Answer:

    Counts the number of missing values in each column of the DataFrame -> Option B
  4. Quick Check:

    df.isna().sum() counts missing per column [OK]
Hint: Use isna() then sum() to count missing per column [OK]
Common Mistakes:
  • Thinking sum() counts rows instead of missing values
  • Confusing isna() with fillna()
  • Assuming it replaces missing values
2. Which of the following is the correct syntax to count all missing values in a pandas DataFrame df?
easy
A. df.isna().count()
B. df.count().sum()
C. df.isna().sum().sum()
D. df.isnull().count()

Solution

  1. Step 1: Use df.isna() or df.isnull() to find missing values

    Both return a boolean DataFrame marking missing values as True.
  2. Step 2: Use .sum().sum() to count all missing values

    The first sum() sums missing per column, the second sums those counts to get total missing in the DataFrame.
  3. Final Answer:

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

    Total missing = df.isna().sum().sum() [OK]
Hint: Double sum() after isna() counts all missing values [OK]
Common Mistakes:
  • Using count() which counts non-missing values
  • Using isna().count() which counts all rows, not missing
  • Confusing isna() with isnull().count()
3. Given the DataFrame df below:
import pandas as pd
data = {'A': [1, None, 3], 'B': [None, None, 6], 'C': [7, 8, 9]}
df = pd.DataFrame(data)

What is the output of df.isna().sum()?
medium
A. A 1 B 1 C 1 dtype: int64
B. A 0 B 0 C 0 dtype: int64
C. A 2 B 1 C 0 dtype: int64
D. A 1 B 2 C 0 dtype: int64

Solution

  1. Step 1: Identify missing values in each column

    Column A has one None (missing), column B has two None values, column C has none.
  2. Step 2: Apply df.isna().sum()

    This counts missing per column: A=1, B=2, C=0.
  3. Final Answer:

    A 1 B 2 C 0 dtype: int64 -> Option D
  4. Quick Check:

    Count missing per column matches output [OK]
Hint: Count None or NaN per column to verify sums [OK]
Common Mistakes:
  • Mixing counts of missing and non-missing
  • Miscounting missing in column B
  • Assuming None counts as zero
4. You run the code below but get an error:
import pandas as pd
data = {'X': [1, 2, None], 'Y': [None, 5, 6]}
df = pd.DataFrame(data)
missing = df.isna.sum()

What is the error and how to fix it?
medium
A. Missing parentheses after isna; fix with df.isna().sum()
B. DataFrame missing columns; add columns before counting
C. sum() is not a pandas method; use count() instead
D. None values cause error; replace with zeros first

Solution

  1. Step 1: Identify the error in method call

    The code uses df.isna.sum() missing parentheses after isna, which is a method.
  2. Step 2: Correct the syntax

    Use df.isna().sum() to call the method and then sum missing values.
  3. Final Answer:

    Missing parentheses after isna; fix with df.isna().sum() -> Option A
  4. Quick Check:

    Method calls need parentheses [OK]
Hint: Remember to add () after isna to call the method [OK]
Common Mistakes:
  • Forgetting parentheses on isna()
  • Using sum() instead of count() incorrectly
  • Thinking None causes errors in counting
5. You have a DataFrame df with columns ['age', 'income', 'score']. You want to find the percentage of missing values in each column. Which code snippet correctly calculates this?
hard
A. df.isna().sum() / len(df) * 100
B. df.isna().count() / len(df) * 100
C. df.count() / df.isna().sum() * 100
D. df.isna().sum() * 100

Solution

  1. Step 1: Count missing values per column

    Use df.isna().sum() to get missing counts per column.
  2. Step 2: Calculate percentage of missing values

    Divide missing counts by total rows len(df) and multiply by 100 to get percentage.
  3. Final Answer:

    df.isna().sum() / len(df) * 100 -> Option A
  4. Quick Check:

    Missing % = (missing count / total rows) * 100 [OK]
Hint: Divide missing count by total rows, multiply by 100 [OK]
Common Mistakes:
  • Using count() which counts non-missing values
  • Multiplying missing count by 100 without dividing
  • Dividing count by missing count incorrectly
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