Sub topic 1
How pandas represents missing values
Prerequisites
This chapter assumes you know basic Python syntax and can create and index a pandas Series and DataFrame. You should also know that np.nan is NumPy's "not a number" value. Later chapters cover how to find, drop and fill missing values. This one covers only how pandas marks them.
Why the marker matters
A missing value is a cell with no usable data. pandas does not use one universal marker for it. The marker depends on the column's dtype (the type of data stored in the column). Knowing which marker you have explains why some columns turn into floats and why some comparisons behave oddly.
The four markers
| Marker | Where you see it | Notes |
|---|---|---|
| `np.nan` | Float columns | A float value meaning "not a number". The classic pandas marker. |
| `None` | Object columns | Python's own "no value". pandas treats it as missing. |
| `pd.NaT` | Datetime and timedelta columns | "Not a Time". The missing marker for time data. |
| `pd.NA` | Nullable dtypes such as `Int64`, `boolean`, `string` | A single marker that works across dtypes. |
All four count as missing for functions such as isna. The sections below show what each one looks like in practice.
NaN and None in one DataFrame
The next example builds a DataFrame with a float column and a text column. Each has gaps.
import numpy as np
import pandas as pd
df = pd.DataFrame({
"name": ["Ana", "Ben", "Cy", "Dee"],
"age": [25, np.nan, 31, np.nan],
"city": ["Oslo", None, "Rome", "Lima"],
})
print(df)
print(df.dtypes)
print(df.isna())
print(df.isna().sum())Look at the age column. You wrote integers and np.nan, but pandas stores the column as float64. NaN is a float, so an integer column with a gap becomes floats. Ages 25 and 31 print as 25.0 and 31.0.
The city column has dtype object. pandas keeps None as it is, and isna reports it as missing. df.isna() returns a DataFrame of True and False values. df.isna().sum() counts the True values in each column, which gives the number of missing cells per column.
Time data uses NaT
In a datetime column, the missing marker is pd.NaT.
import pandas as pd
dates = pd.Series(pd.to_datetime(["2026-01-05", None, "2026-03-20"]))
print(dates)
print(dates.isna())The output shows NaT in the second row. It plays the same role as NaN does for floats, so isna detects it too.
pd.NA, the newer marker
NaN only fits float columns, so integer, boolean and string data cannot hold it without changing type. pandas solves this with nullable dtypes. These dtypes use pd.NA as their marker. Their names start with a capital letter, such as Int64, to tell them apart from the NumPy types.
import pandas as pd
s = pd.Series([1, None, 3], dtype="Int64")
print(s)
print(s.dtype)
print(s.isna())The values stay integers, and the gap shows as <NA>. A later chapter covers nullable dtypes in full. For now, remember that pd.NA lets integer, boolean and string columns keep their type.
NaN is not equal to anything
NaN follows the floating-point rule that it is never equal to any value, including itself. This catches many learners out.
import numpy as np
import pandas as pd
s = pd.Series([1.0, np.nan, 3.0])
print(s == np.nan)
print(s.isna())The first line prints False for every row, even the missing one. The comparison cannot find the gap. Use isna or notna instead.
How the pieces fit together
Common mistakes
- Expecting an integer column to stay integer after a gap appears. With NumPy dtypes it becomes
float64. Use a nullable dtype such asInt64to prevent this. - Testing with
== np.nan. It always givesFalse. - Assuming an empty string
""is missing. pandas treats it as ordinary text, soisnareturnsFalsefor it.
Exercise
A Series is created with pd.Series([10, None, 30]). What dtype does it have, which marker represents the gap, and how would you keep the values as integers?
Show answer
The dtype is float64, because None in a numeric list becomes np.nan and integers are upcast to floats. The marker is np.nan. To keep integers, create it with pd.Series([10, None, 30], dtype="Int64"), which uses pd.NA for the gap.
Exercise
Why does (pd.Series([1.0, np.nan]) == np.nan).sum() return 0, and what should you use to count the missing values?
Show answer
NaN is never equal to anything, including itself, so every comparison is False and the sum is 0. Use pd.Series([1.0, np.nan]).isna().sum(), which returns 1.