Missing values and dtypes
Quick answer
Missingness means a value is unavailable, not necessarily zero. pandas uses several missing markers including None, NaN, NaT and pd.NA, depending on dtype. The nullable Int64 dtype (capital I) retains integer values alongside missing entries. Use isna() to detect missingness, not equality comparisons. Examples run locally on Python 3.13.5 and pandas 2.2.3; ByteMind package support is not verified. All data are synthetic.
Count missing values without erasing zeros
Specify nullable integer storage. Count each column separately before deciding how to handle gaps.
import pandas as pdframe = pd.DataFrame({'count': pd.Series([0, None, 4], dtype='Int64'), 'site': ['A', None, 'B']})print(str(frame['count'].dtype))print(frame.isna().sum().to_dict())print(frame['count'].fillna(-1).tolist())Expected output (pandas 2.2.3):
Int64{'count': 1, 'site': 1}[0, -1, 4]Zero remains a real measurement. The -1 replacement is only an illustration of an explicitly reserved sentinel; it is not a default ML imputation recommendation.
Parse numeric text and audit failures
to_numeric converts valid numeric text. With errors="coerce", malformed values become missing. Distinguish a parsing failure from a value that was already missing.
import pandas as pdraw = pd.Series(['12', 'bad', None, '0'])parsed = pd.to_numeric(raw, errors='coerce')failed = raw.notna() & parsed.isna()print(failed.tolist())print(int(parsed.isna().sum()))print(parsed.dropna().tolist())Expected output (pandas 2.2.3):
[False, True, False, False]2[12.0, 0.0]One row failed parsing and another was already missing. dropna is used only to display observed values, not to silently remove training rows.
Common mistakes
Do not use fillna(0) automatically. Missingness may carry information and deleting rows can change the population. If imputation uses a mean or median, fit it on training data only and reuse the fitted value on validation and test data. Track parsing errors separately from original nulls.
Practice and next steps
For [0, None, 5, None], report observed and missing counts. Explain which missingness policy requires domain knowledge. Try the pure-Python reasoning challenge and knowledge check separately; these do not assess pandas API execution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Missing values and dtypes — knowledge check
Apply tabular data reasoning to new synthetic fixtures.
Which test detects missing values across supported pandas dtypes?
Which dtype stores integers with pd.NA?
For [0, None, 5], how many values are observed?
What does to_numeric(errors="coerce") do to malformed text?
Where should a median imputation value be fitted?