Column A has one None (missing), column B has two None values, column C has none.
Step 2: Apply df.isna().sum()
This counts missing per column: A=1, B=2, C=0.
Final Answer:
A 1
B 2
C 0
dtype: int64 -> Option D
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
Step 1: Identify the error in method call
The code uses df.isna.sum() missing parentheses after isna, which is a method.
Step 2: Correct the syntax
Use df.isna().sum() to call the method and then sum missing values.
Final Answer:
Missing parentheses after isna; fix with df.isna().sum() -> Option A
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
Step 1: Count missing values per column
Use df.isna().sum() to get missing counts per column.
Step 2: Calculate percentage of missing values
Divide missing counts by total rows len(df) and multiply by 100 to get percentage.