What a blank does to count, sum and mean
Two AIs give 4.2 and 2.6 for the same ratings. Explain how blanks moved each number, and choose the one that matches what a blank means.
2 parts · 3 and 7 min
Free course. Your Maestro, an AI, .
In the last module, every percentage and rate came down to one question: what is the denominator? Before reading on, recall the warehouse case: what did you divide each warehouse's returns by, and what did that change? An average has a denominator too, even when the code shows no division sign, and blank cells can change that denominator without warning.
After an eight-person workshop, two colleagues asked two AIs for the average feedback rating from the same eight forms, F1 through F8. Each form asked attendees to rate the session on a scale from 1 to 5. One AI reported an average of 4.2. The other reported 2.6 (2.62 when rounded to two decimal places).
How blanks move the count and the average
In the table below, the eight forms hold the ratings 5, 4, None, 3, None, 5, 4, and None. Five attendees circled a score (F1, F2, F4, F6, and F7), and three left the rating line empty (F3, F5, and F8). In Glossary word, those three empty cells are stored as missing values (None in Python, displayed as NaN in a DataFrame).
When the first AI summarized the table, four common operations handled those three blanks differently:
len(forms)counts every row in the DataFrame whether its cells are filled or empty, so it prints 8.forms["rating"].count()counts only the non-blank cells in theratingcolumn, so it prints 5.forms["rating"].sum()adds the five recorded numbers (5 + 4 + 3 + 5 + 4) and ignores the blanks, printing 21.0.forms["rating"].mean()computes the Glossary word by dividing.sum()by.count(), which is 21 divided by 5, or 4.2.
The second AI chained fillna(0) before taking the average: forms["rating"].fillna(0).mean(). Calling fillna(0) replaces every blank cell with 0, turning the column into 5, 4, 0, 3, 0, 5, 4, and 0.
Adding three zeros leaves .sum() unchanged at 21.0. What changes is the divisor inside .mean(). Because the three blanks have been replaced with the number 0, .count() rises from 5 to 8. Dividing the same total of 21 by 8 instead of 5 drops the average from 4.2 to 2.625, which round(2.625, 2) prints as 2.62. If the shift from 4.2 to 2.62 still feels sudden, ask your Maestro to trace the numerator and denominator before and after fillna(0).
Decide from what a blank means on the form
Whether you skip blanks or fill them with zero depends on what an empty cell stands for in the real world. If a daily sales log leaves a cell blank whenever a representative closes zero deals that day, the blank really stands for 0, and fillna(0) gives the true daily average.
On this workshop feedback form, the rating scale runs from 1 to 5. Zero does not appear on the sheet. When F3, F5, and F8 are blank, those three attendees skipped the question rather than rating the workshop below 1. Filling their rows with 0 invents three scores below the bottom of the scale. The accurate report gives the 4.2 average across the 5 answered forms and states how many were left blank: 4.2 out of 5 across 5 completed ratings, with 3 of 8 forms unanswered.
Common mistake: len() counts rows; .count() counts non-blank values
When a column has missing values, len(forms) and forms["rating"].count() return different numbers: 8 rows in the table, 5 ratings actually filled in. Because .mean() divides by .count(), replacing blanks with 0 increases the denominator from 5 to 8 while adding nothing to the sum.
A good place to stop. Up next: part 2 of 2 · 7 min
Try it
Run the script below to see len(forms), .count(), .sum(), and .mean() on the eight workshop forms. Then uncomment the last line to print the average when blanks are filled with 0, and compare the two averages.
Your output should print Rows: 8, Answered: 5, Sum: 21.0, Mean: 4.2, and Mean, blanks as 0: 2.62 (Python rounds 2.625 to the nearest even hundredth, 2.62). A complete explanation names how the three blanks affect all three summary numbers: they leave the sum at 21.0, they are excluded from count() (5 instead of 8 rows), and filling them with 0 changes the mean from 21 / 5 = 4.2 to 21 / 8 = 2.625 by adding 3 to the divisor. If you want to check how you would explain the choice between 4.2 and 2.62 to a colleague, try your wording with your Maestro.