liveBook · Manning

Nan

As explained in Statistics Every Programmer Needs

NaN is a special floating-point value representing a numerical result that is undefined or cannot be represented as a valid number.

NaN, or “Not a Number,” is a special floating-point value for undefined or unrepresentable numerical results. In play-by-play data, it can mark plays where no yards were available or where a play gained zero yards. section 6.2.2

Handle NaN values according to the meaning of the underlying data:

  • Replace NaN with zero when the domain supports that interpretation, such as recording zero yards for a completed running or passing play. section 6.2.2
  • Treat imputation as a modeling decision: inappropriate replacement can create excess zeros, distort minima, and affect predictions. section 6.2.2
>>> nfl_pbp['YARDS_GAINED'] = nfl_pbp['YARDS_GAINED'].fillna(0)

Use pandas fillna() to replace NaN values in YARDS_GAINED when zero is an appropriate domain interpretation. section 6.2.2

How Statistics Every Programmer Needs covers it

How deep it goes
Defines NaN, demonstrates contextual replacement, and warns that imputation can distort predictions.
Examples
Uses NFL play-by-play yards, timeouts, zero-yard plays, and pandas fillna(0).
What it assumes
Assumes tabular data analysis and teaches NaN’s meaning through a concrete yards-gained example.
What you can do after
Apply it via pandas by imputing NaN values when the domain justifies the replacement.
How it connects
Connects missing values with imputation, data preprocessing, and model predictions.

Also explained in

Compare how 9 books explain nan →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.