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 None is preferred over v == None because == can be overridden by custom __eq__; is tests object identity and is always safe for None checks.
  • pd.Series(values, dtype=float) makes the numeric dtype explicit. pandas already infers float64 (replacing None with NaN) for a numeric list like this one, so the dtype=float argument is defensive rather than corrective — it documents intent and guards against edge cases where inference might choose object (e.g. a list containing mixed types).
  • int(s.isna().sum()) casts the NumPy scalar to a plain Python int so the RESULT tuple round-trips through ast.literal_eval unchanged.