Why does df.isna() return a DataFrame of True/False instead of numbers?
df.isna() checks each cell and returns True if missing, False otherwise, as shown in execution_table step 2. This boolean mask helps count missing values.
How does sum() count missing values when applied to booleans?
In Python, True counts as 1 and False as 0. So sum() adds up True values per column, giving the count of missing values (execution_table step 3).
Can we count missing values for the whole DataFrame at once?
Yes, by adding .sum().sum() after isna(), you get total missing values in the entire DataFrame, but here we count per column first (not shown in this trace).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the missing count for column 'B'?
A1
B2
C3
D0
💡 Hint
Check the sum() Result column in execution_table row with Step 3.
According to variable_tracker, what is the value of missing_mask after step 2?
Look at the missing_mask row under After Step 2 column in variable_tracker.
If the DataFrame had no missing values, what would be the sum() result?
A{'A':3, 'B':3}
B{'A':1, 'B':1}
C{'A':0, 'B':0}
DNone
💡 Hint
Recall that sum() counts True values; no missing means all False, so sum is zero.
Concept Snapshot
Counting missing values in pandas:
- Use df.isna() to get True/False mask of missing cells.
- Use .sum() on mask to count missing per column.
- True counts as 1, False as 0 in sum.
- Use .sum().sum() for total missing in DataFrame.
- Useful to find data quality issues quickly.
Full Transcript
We start with a DataFrame containing some missing values. Using df.isna(), we create a mask showing True where values are missing and False otherwise. Then, summing this mask per column counts how many missing values each column has. This works because True counts as 1 and False as 0 in sums. The final result is a count of missing values per column. This method helps quickly identify where data is incomplete.