Missing Values
Detect Missing
Identify which positions in a list of sensor readings are missing (None)
and count how many are absent. The replay shows flags growing one boolean
at a time and count incrementing only on missing values.
By hand
With pandas
Load the values into a pd.Series. isna() returns a boolean Series
marking each missing position; .tolist() converts it to a plain list and
.sum() counts the True entries.
naive.py
values = [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]
flags = []
count = 0
for v in values:
missing = v is None
flags.append(missing)
if missing:
count = count + 1
print('RESULT:', (count, flags))
library.py
import pandas as pd
from dalib.display import set_display
set_display()
values = [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]
s = pd.Series(values, dtype=float)
flags = s.isna().tolist()
count = int(s.isna().sum())
print('RESULT:', (count, flags))
RESULT: (3, [False, True, False, True, False, True, False, False])
Implementation notes
v is Noneis preferred overv == Nonebecause==can be overridden by custom__eq__;istests object identity and is always safe forNonechecks.pd.Series(values, dtype=float)makes the numeric dtype explicit. pandas already infersfloat64(replacingNonewithNaN) for a numeric list like this one, so thedtype=floatargument is defensive rather than corrective — it documents intent and guards against edge cases where inference might chooseobject(e.g. a list containing mixed types).int(s.isna().sum())casts the NumPy scalar to a plain Pythonintso the RESULT tuple round-trips throughast.literal_evalunchanged.