liveBook · Manning

Missing value

As explained in Outlier Detection in Python

The absence of an expected value or observation in a dataset.

A missing value is an absent observation where a value might be expected. It can mean “not applicable,” as when eldest-child age is absent for a person with no children, or “unknown,” as when a true age was not collected. section 9.1

Missingness can itself carry information. Rare nulls may form useful outliers, and nonrandom failures—such as temperature sensors failing at extreme temperatures—can reveal conditions associated with the absence. Filling the value should therefore preserve an indicator that it was missing. section 9.1

A practical treatment separates interpretation from imputation:

  • Identify whether the absence is legitimate or a data artifact caused by inaccessible information, joins, appends, or processing errors. section 9.1
  • Record missingness before filling values, using per-column indicators or a row-level count of missing fields. section 9.1
  • Fill numeric values with a median and categorical values with a mode when a detector requires complete input; treat these as preprocessing choices rather than recovered truth. section 9.0 section 9.1
  • Separate likely data artifacts before identifying statistical outliers in the remaining data, because missingness and unusual values may represent different problems. section 9.1

A conditional absence

In a table containing Number of Children and Age of Eldest Child, a zero child count with a missing eldest-child age is expected. A positive child count with the same missing age indicates an unknown value or collection problem and deserves separate attention. section 9.1

Listing 9.1 Filling None and NaN values
import pandas as pd
import numpy as np
 
df = pd.DataFrame({"A": [1, 2, np.NaN, 4, 5, None], 
                   "B": ['A', 'B', None, "B", "B", "F"]})
df_filled = df.copy()
df_filled['A Null'] = df['A'].isna()
df_filled['B Null'] = df['B'].isna()
df_filled['Num Null'] = df.isna().sum(axis=1)
df_filled['A'] = df['A'].fillna(df['A'].median())
df_filled['B'] = df['B'].fillna(df['B'].mode()[0])
print(df_filled)

Shows how to preserve null flags, count missing fields, and fill numeric and categorical columns with median and mode values. section 9.1

How Outlier Detection in Python covers it

How deep it goes
Distinguishes legitimate, unknown, and artifact-driven absence, then gives indicator and imputation procedures without deriving imputation theory.
Examples
Uses eldest-child age, failing temperature sensors, pandas null flags, row counts, median filling, and mode filling.
What it assumes
Assumes tabular features and basic preprocessing knowledge while teaching the distinction between not applicable and unknown values.
What you can do after
Operate/configure pandas preprocessing that flags, counts, and fills missing numeric and categorical values before outlier detection.
How it connects
Connects missing values to data quality, imputation, outlier detection, preprocessing, and collective outliers.

Also explained in

Compare how 35 books explain missing value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.