These are the notes for Data Analytics with Python, episode 19, the first hands-on cleaning episode. Last episode's quality scorecard said some values were missing. Here we learn to find missing values (isna, notna, isnull), recognise their four faces (NaN, None, pd.NA, NaT), measure them (count and percentage), drop them carefully (dropna with how, thresh, subset), fill them sensibly (fillna, mean / median / mode and group-wise imputation, ffill, bfill, interpolate), and, most important, ask why they are missing (MCAR, MAR, MNAR) and keep a missingness indicator column. Every term is defined the first time it appears and collected in the Glossary. Every program below was run for real (Python 3.13, pandas 3.0.5, NumPy 2.5.3); outputs are unedited.
The problem: blanks in the register
Think of a class register: P, A, P, and then one empty box. That empty box is a missing value: a place where a value should be, but nobody recorded one. Is the student absent? Present, and the teacher forgot? You don't know. A blank is not a zero and not an absence: it is unknown.
Ramesh kept a 10-day log at his tea stall: temperature, cups sold, price per cup, payment type and the customer rating. His helpers skipped boxes. The log is read with read_csv (episode 13); io.StringIO makes a piece of text behave like a file:
import sys; sys.tracebacklimit = 0
import pandas as pd, numpy as np, io
raw = """day,temp,cups,price,pay,rating
1,24.0,320,20,UPI,4
2,,280,20,Cash,
3,22.5,,20,UPI,5
4,21.0,300,,,3
5,,,,,
6,19.5,350,25,UPI,
7,20.0,390,25,Card,4
8,,410,25,UPI,2
9,18.0,,25,Cash,
10,17.5,450,25,UPI,5
"""
log = pd.read_csv(io.StringIO(raw))
(sys.tracebacklimit = 0 only hides pandas' long internal traceback, so errors are one short line.)
Finding missing values: why == np.nan fails
pandas shows each blank as NaN, short for Not a Number. The obvious way to count missing temperatures is to compare with np.nan:
print(log)
print((log["temp"] == np.nan).sum(), "missing temps?")
day temp cups price pay rating
0 1 24.0 320.0 20.0 UPI 4.0
1 2 NaN 280.0 20.0 Cash NaN
2 3 22.5 NaN 20.0 UPI 5.0
3 4 21.0 300.0 NaN NaN 3.0
4 5 NaN NaN NaN NaN NaN
5 6 19.5 350.0 25.0 UPI NaN
6 7 20.0 390.0 25.0 Card 4.0
7 8 NaN 410.0 25.0 UPI 2.0
8 9 18.0 NaN 25.0 Cash NaN
9 10 17.5 450.0 25.0 UPI 5.0
0 missing temps?
We can see three NaN temperatures, but the count is 0, with no error. The reason: NaN is not equal to anything, not even to another NaN. That is a rule of decimal-number arithmetic (the IEEE 754 standard), not a pandas bug.
print(np.nan == np.nan)
print(log["temp"].isna().sum(), "missing temps")
print(log["temp"].isna().tolist())
False
3 missing temps
[False, True, False, False, True, False, False, True, False, False]
isna() ("is N/A", is not available) returns True for every missing value and False otherwise. Its partner notna() is the exact opposite. isnull() and notnull() are just other names for the same methods.
Also notice the dtypes: cups holds whole numbers, but pandas printed 320.0. A classic integer column cannot store a blank, so pandas stored the column as decimals (float64). Episode 20 fixes that with nullable types.
The four faces of "missing"
| Looks like | Name | Used for | Comes from |
|---|---|---|---|
NaN / nan |
Not a Number | decimal (float64) columns, and text columns in pandas 3 |
NumPy |
None |
Python's "nothing" value | plain Python objects | Python |
<NA> |
pd.NA |
nullable types: Int64, boolean, string |
pandas |
NaT |
Not a Time | dates and times | pandas |
s = pd.Series([1.5, None, 3.0])
t = pd.Series(["UPI", None, "Cash"])
d = pd.to_datetime(pd.Series(["2026-10-01", None]))
n = pd.Series([4, None, 5], dtype="Int64")
for x in [s, t, d, n]:
print(x.dtype, "->", x.tolist(), x.isna().tolist())
float64 -> [1.5, nan, 3.0] [False, True, False]
str -> ['UPI', nan, 'Cash'] [False, True, False]
datetime64[us] -> [Timestamp('2026-10-01 00:00:00'), NaT] [False, True]
Int64 -> [4, <NA>, 5] [False, True, False]
Every Series was built with a None in the middle, and pandas converted it to the right blank for each type. isna() recognises all of them, so you never need to know which face you are looking at.
A missing-value report
Measure before you fix. isna() gives a table of True/False; sum() counts the Trues (True counts as 1) and mean() gives the share of Trues, so × 100 is the missing percentage:
report = pd.DataFrame({
"missing": log.isna().sum(),
"pct": (log.isna().mean() * 100).round(1),
})
print(report)
print(log.notna().sum().sum(), "filled cells")
print(log.isnull().equals(log.isna()))
missing pct
day 0 0.0
temp 3 30.0
cups 3 30.0
price 2 20.0
pay 2 20.0
rating 4 40.0
46 filled cells
True
notna().sum().sum() sums twice: first per column, then over all columns. isnull() gives exactly the same table as isna().
Dropping: dropna
The obvious fix is to delete every row with a blank:
print(len(log), "rows before")
print(len(log.dropna()), "rows after dropna()")
print(log.dropna())
10 rows before
3 rows after dropna()
day temp cups price pay rating
0 1 24.0 320.0 20.0 UPI 4.0
6 7 20.0 390.0 25.0 Card 4.0
9 10 17.5 450.0 25.0 UPI 5.0
Seventy percent of the data is gone, because by default dropna() removes a row if any value in it is missing. Three settings let you drop with a rule:
| Setting | Meaning |
|---|---|
how="any" (default) |
drop the row if any value is missing |
how="all" |
drop the row only if every value is missing |
thresh=k |
keep a row only if it has at least k real (non-missing) values |
subset=[cols] |
look only at these columns when deciding |
print(len(log.dropna(how="all")), "rows with how='all'")
print(log.dropna(thresh=2)["day"].tolist())
print(log.dropna(thresh=5)["day"].tolist())
print(log.dropna(subset=["cups"])["day"].tolist())
10 rows with how='all'
[1, 2, 3, 4, 6, 7, 8, 9, 10]
[1, 3, 6, 7, 8, 10]
[1, 2, 4, 6, 7, 8, 10]
A surprise: how="all" kept all 10 rows. Day 5 is empty except for the day number, so it is not "all missing". thresh=2 removes exactly day 5. subset=["cups"] removes only the days with no cups count, which is what you want if your question is about cups. dropna returns a new DataFrame; the original log is unchanged.
When is dropping fine? When only a few rows are affected and the blanks are random (MCAR, below). Otherwise you lose data and can bias the result.
Filling: imputation with fillna
A student missed one test, so the teacher uses the class median as a stand-in. Filling a blank with a sensible estimate is called imputation, and the pandas method is fillna(value).
Filling with 0: a silent mistake
print("mean of real temps:", log["temp"].mean())
print("after fillna(0): ", log["temp"].fillna(0).mean())
mean of real temps: 20.357142857142858
after fillna(0): 14.25
mean() skips NaN, so the real average is about 20.4 °C. Filling with 0 invents three freezing days and drags the average to 14.25. Zero is a real value, not a blank. Use 0 only when a blank truly means zero (for example, "no refunds" in a refunds column).
Mean and median imputation
The mean is the average (sum ÷ count). The median is the middle value after sorting; one extreme value cannot pull it far, so it is the safer default for numbers.
t = log["temp"]
print("mean:", round(t.mean(), 2), " median:", t.median())
filled = t.fillna(t.median())
print(filled.tolist())
mean: 20.36 median: 20.0
[24.0, 20.0, 22.5, 21.0, 20.0, 19.5, 20.0, 20.0, 18.0, 17.5]
Mode imputation for text, and the mode()[0] trap
Text has no mean. The mode is the most common value. Series.mode() returns a Series (there can be ties), not a single value:
print(log["pay"].mode())
print(log["pay"].fillna(log["pay"].mode()).tolist())
0 UPI
Name: pay, dtype: str
['UPI', 'Cash', 'UPI', nan, nan, 'UPI', 'Card', 'UPI', 'Cash', 'UPI']
Nothing was filled, and there was no error. When fillna gets a Series, it fills each row with the value at the same index label. The mode Series only has label 0, and row 0 isn't blank. Take the first value with [0]:
top = log["pay"].mode()[0]
print(top)
print(log["pay"].fillna(top).tolist())
UPI
['UPI', 'Cash', 'UPI', 'UPI', 'UPI', 'UPI', 'Card', 'UPI', 'Cash', 'UPI']
Data in time order: ffill, bfill, interpolate
If a thermometer skipped a day, you'd look at yesterday and tomorrow. Old tutorials write fillna(method="ffill"); pandas 3 removed that argument:
print(log["temp"].fillna(method="ffill"))
TypeError: NDFrame.fillna() got an unexpected keyword argument 'method'
The methods are now separate:
ffill()(forward fill) copies the last known value forward.bfill()(backward fill) copies the next known value backward.interpolate()draws a straight line between the known neighbours (linear interpolation).
t = log["temp"]
out = pd.DataFrame({"temp": t, "ffill": t.ffill(),
"bfill": t.bfill(), "interp": t.interpolate()})
print(out)
temp ffill bfill interp
0 24.0 24.0 24.0 24.00
1 NaN 24.0 22.5 23.25
2 22.5 22.5 22.5 22.50
3 21.0 21.0 21.0 21.00
4 NaN 21.0 19.5 20.25
5 19.5 19.5 19.5 19.50
6 20.0 20.0 20.0 20.00
7 NaN 20.0 18.0 19.00
8 18.0 18.0 18.0 18.00
9 17.5 17.5 17.5 17.50
Day 2 sits between 24 and 22.5: ffill says 24, bfill 22.5, interpolate 23.25 (halfway). For a slowly changing reading like temperature, interpolation is the most believable. For a value that stays the same until it changes (a price, a plan, a status), ffill is right. These methods only make sense when rows are sorted in time order.
Group-wise imputation
One median for different kinds of things is wrong:
import pandas as pd, numpy as np
menu = pd.DataFrame({
"item": ["chai", "chai", "coffee", "coffee", "chai", "coffee"],
"price": [20, np.nan, 40, 45, 20, np.nan]})
menu["overall"] = menu["price"].fillna(menu["price"].median())
med = menu.groupby("item")["price"].transform("median")
menu["by_item"] = menu["price"].fillna(med)
print(menu)
item price overall by_item
0 chai 20.0 20.0 20.0
1 chai NaN 30.0 20.0
2 coffee 40.0 40.0 40.0
3 coffee 45.0 45.0 45.0
4 chai 20.0 20.0 20.0
5 coffee NaN 30.0 42.5
The overall median (30) gives the missing chai a price no chai has. Group-wise imputation fills each blank with a statistic of its own group. groupby("item") splits the rows into one group per item; transform("median") computes each group's median and hands it back on every row of that group, so the result lines up with the original rows. groupby gets two full episodes (24 and 25).
Why is it missing? MCAR, MAR, MNAR
The statistician Donald Rubin (1976) named three mechanisms of missing data. Using the rating tablet at Ramesh's stall:
| Name | Stands for | Meaning | Rating example | Safe to drop or fill simply? |
|---|---|---|---|---|
| MCAR | Missing Completely At Random | blanks have nothing to do with any value, seen or unseen | the tablet freezes at random moments | yes: results stay unbiased (you just have less data) |
| MAR | Missing At Random | blanks depend on other columns you recorded | on rush days (high cups) nobody has time to rate |
fill using those columns (group-wise, models); simple dropping can bias |
| MNAR | Missing Not At Random | blanks depend on the missing value itself | unhappy customers walk away without rating | no formula can fix it: collect differently, or report it |
The name MAR is confusing: it does not mean "random". It means "explained by data you have".
A simulation with 1,000 true ratings (1 to 5). rng.integers draws random whole numbers (episode 10), and mask(cond) replaces values with NaN wherever cond is True:
import pandas as pd, numpy as np
rng = np.random.default_rng(7)
true = pd.Series(rng.integers(1, 6, 1000))
mcar = true.mask(rng.random(1000) < 0.3)
mnar = true.mask((true <= 2) & (rng.random(1000) < 0.8))
print("true mean:", round(true.mean(), 2))
print("MCAR mean:", round(mcar.mean(), 2), mcar.isna().sum(), "missing")
print("MNAR mean:", round(mnar.mean(), 2), mnar.isna().sum(), "missing")
true mean: 3.05
MCAR mean: 3.09 310 missing
MNAR mean: 3.73 305 missing
Almost the same number of blanks, very different damage. With random blanks the average is almost right (3.09). When unhappy customers hide, the average jumps to 3.73, and filling the blanks with that mean keeps it at 3.73. You can never prove MNAR from the data alone; you reason about how the data was collected.
Missingness indicator column
Before filling, save a True/False column that remembers where the blanks were. This is a missingness indicator column (or flag):
log["rating_missing"] = log["rating"].isna()
log["rating"] = log["rating"].fillna(log["rating"].median())
print(log[["day", "rating", "rating_missing"]])
print(log.groupby("rating_missing")["cups"].mean())
day rating rating_missing
0 1 4.0 False
1 2 4.0 True
2 3 5.0 False
3 4 3.0 False
4 5 4.0 True
5 6 4.0 True
6 7 4.0 False
7 8 2.0 False
8 9 4.0 True
9 10 5.0 False
rating_missing
False 374.0
True 315.0
Name: cups, dtype: float64
The filled ratings say 4, but the flag remembers they were guesses. And the days with a missing rating sold fewer cups on average (315 vs 374): the blanks are linked to another column, a hint that they are not MCAR. Without the flag, that evidence would be gone. Flags are also useful later in machine learning, where "was missing" can itself predict something.
Mini project: clean_log()
One function that applies today's decisions, column by column (run on the original log):
def clean_log(df):
df = df.dropna(thresh=2).copy()
df["rating_missing"] = df["rating"].isna()
df["temp"] = df["temp"].interpolate()
df["price"] = df["price"].ffill()
df["pay"] = df["pay"].fillna(df["pay"].mode()[0])
return df
clean = clean_log(log)
print(clean)
print(clean.isna().sum().to_dict())
day temp cups price pay rating rating_missing
0 1 24.00 320.0 20.0 UPI 4.0 False
1 2 23.25 280.0 20.0 Cash NaN True
2 3 22.50 NaN 20.0 UPI 5.0 False
3 4 21.00 300.0 20.0 UPI 3.0 False
5 6 19.50 350.0 25.0 UPI NaN True
6 7 20.00 390.0 25.0 Card 4.0 False
7 8 19.00 410.0 25.0 UPI 2.0 False
8 9 18.00 NaN 25.0 Cash NaN True
9 10 17.50 450.0 25.0 UPI 5.0 False
{'day': 0, 'temp': 0, 'cups': 2, 'price': 0, 'pay': 0, 'rating': 3, 'rating_missing': 0}
.copy()makes sure we change our own copy, never the caller's DataFrame (episode 14).cupsandratingkeep their blanks on purpose: we don't invent sales, and ratings are flagged. The goal is honest data, not zero NaNs.- Each decision belongs in the cleaning log (episode 18): "dropped day 5 (empty); interpolated 2 temps; carried 1 price forward; filled 1 payment with mode".
Decision guide
- Measure:
isna().sum(),isna().mean() * 100. - Ask why: MCAR, MAR or MNAR? Talk to whoever collected the data.
- Few blanks, MCAR →
dropna(subset=[...])is fine. - Numbers → median (or mean if no outliers). Text →
mode()[0]or an explicit"Unknown". Groups differ → group median withgroupby+transform. - Time order →
ffill(steps),interpolate(smooth readings),bfill(rarely, for the first rows). - Flag before you fill, and write it in the cleaning log.
Common mistakes
| Code / habit | Real error / symptom | Why | Fix |
|---|---|---|---|
log["temp"] == np.nan |
no error; all False; count 0 | NaN is never equal to anything | log["temp"].isna() |
fillna(df["pay"].mode()) |
no error; blanks stay nan |
mode() is a Series, matched by index |
fillna(df["pay"].mode()[0]) |
fillna(method="ffill") |
TypeError: NDFrame.fillna() got an unexpected keyword argument 'method' |
removed in pandas 3 | .ffill() / .bfill() |
log["temp"].fillna(0) |
no error; mean 20.36 → 14.25 | 0 is a real value | median, interpolate(), or leave blank |
log.dropna() with no settings |
no error; 10 rows → 3 | any blank drops the row | subset=, thresh= |
dropna(how="all") to remove an empty day |
no error; nothing dropped | the day column is never blank |
thresh=2 or subset=[...] |
| One overall median for every group | chai filled with ₹30 | groups have different typical values | groupby(...).transform("median") |
| Filling without a flag | evidence lost | you can't tell real from guessed values | add col_missing = col.isna() first |
Practice
All practice questions use this register:
import pandas as pd, numpy as np, io
raw = """student,class,maths,science,attend
Asha,7A,81,77,0.95
Ravi,7A,,68,0.90
Meena,7B,92,,
Kabir,7B,,,0.60
Zoya,7A,74,80,0.85
Dev,7B,55,61,
"""
reg = pd.read_csv(io.StringIO(raw))
1. Build a missing report: count and percentage per column.
Solution
print(reg.isna().sum())
print((reg.isna().mean() * 100).round(1))
student 0
class 0
maths 2
science 2
attend 2
dtype: int64
student 0.0
class 0.0
maths 33.3
science 33.3
attend 33.3
dtype: float64
2. (a) Keep only students who have a maths mark. (b) Keep only rows with at least 4 real values.
Solution
print(reg.dropna(subset=["maths"])["student"].tolist())
print(reg.dropna(thresh=4)["student"].tolist())
['Asha', 'Meena', 'Zoya', 'Dev']
['Asha', 'Ravi', 'Zoya', 'Dev']
Meena and Kabir have only 3 real values each (name, class and one more).
3. Flag missing maths marks, then fill each with the median of the student's own class.
Solution
reg2 = reg.copy()
reg2["maths_missing"] = reg2["maths"].isna()
reg2["maths"] = reg2["maths"].fillna(reg2.groupby("class")["maths"].transform("median"))
print(reg2[["student", "class", "maths", "maths_missing"]])
student class maths maths_missing
0 Asha 7A 81.0 False
1 Ravi 7A 77.5 True
2 Meena 7B 92.0 False
3 Kabir 7B 73.5 True
4 Zoya 7A 74.0 False
5 Dev 7B 55.0 False
7A's known marks are 81 and 74 (median 77.5); 7B's are 92 and 55 (median 73.5).
4. For temps = pd.Series([30.0, np.nan, np.nan, 27.0, np.nan]), print ffill, bfill and interpolate. Which one leaves a blank, and why?
Solution
temps = pd.Series([30.0, np.nan, np.nan, 27.0, np.nan])
print(temps.ffill().tolist(), temps.bfill().tolist(), temps.interpolate().tolist())
[30.0, 30.0, 30.0, 27.0, 27.0] [30.0, 27.0, 27.0, 27.0, nan] [30.0, 29.0, 28.0, 27.0, 27.0]
bfill leaves the last value blank: there is no next value to copy back. interpolate draws 30 → 29 → 28 → 27 and, past the last known value, repeats it.
5. Fill the blank in pd.Series(["A", None, "B", "A"]) with the most common value.
Solution
s = pd.Series(["A", None, "B", "A"])
print(s.fillna(s.mode()[0]).tolist())
['A', 'A', 'B', 'A']
6. (Thinking) An online survey asks for monthly income; high earners often skip it. MCAR, MAR or MNAR? What would you do?
Solution
MNAR: whether income is missing depends on the income itself. Filling with the median would understate incomes. Report the missing share, compare respondents with non-respondents on columns you do have (city, job), and if income matters, collect it differently (ranges instead of exact numbers, or an optional anonymous question).
Quick quiz
s = pd.Series([4, np.nan, 2])
print(s.mean(), s.fillna(0).mean())
A. 3.0 2.0 B. 2.0 2.0 C. nan 2.0 D. 3.0 3.0
Answer
A. 3.0 2.0. mean() skips NaN, so it averages 4 and 2. After fillna(0) there are three values (4, 0, 2), so the mean is 2.0.
Interview questions
- How do you find missing values in pandas?
isna()/notna()(aliasesisnull()/notnull());df.isna().sum()per column,df.isna().mean()for the share. - Why doesn't
df[col] == np.nanwork? NaN is not equal to anything, including itself (IEEE 754 floating-point rule), so the comparison is always False. - NaN vs None vs pd.NA vs NaT? NaN: float missing value from NumPy. None: Python's null object. pd.NA: pandas' missing marker for nullable dtypes (Int64, boolean, string). NaT: missing datetime.
isna()detects all of them. - When would you drop rows with missing values, and when fill them? Drop when few rows are affected and missingness is random (MCAR) or the row is useless; fill when dropping would lose too much data or bias results, using a method that fits the column and the reason it's missing.
- What do
how,threshandsubsetdo indropna?how="any"/"all": drop if any / all values are missing.thresh=k: keep rows with at least k non-missing values.subset: only consider these columns. - Mean vs median imputation? Median is robust to outliers and skew; mean is fine for symmetric data. Both shrink the spread of the column, so flag imputed values.
- Explain MCAR, MAR and MNAR with an example. MCAR: a sensor fails at random. MAR: older users skip an app question (age is recorded). MNAR: people with high income skip the income question.
- What is group-wise imputation and how do you do it in pandas? Filling with a statistic of the row's own group:
df[col].fillna(df.groupby(g)[col].transform("median")). - ffill vs interpolate? ffill repeats the last known value (good for step-like values: price, status); interpolate estimates between neighbours (good for smooth readings: temperature). Both need time order.
- Why add a missingness indicator column? It keeps the information that a value was imputed, lets you check whether missingness relates to other columns, and can be a useful feature in models.
Glossary
| Term | Meaning | Example |
|---|---|---|
| Missing value | A place where a value should be but none was recorded | an empty box in a register |
| NaN | "Not a Number": NumPy's missing value for decimals (also used for text in pandas 3) | np.nan |
None |
Python's own "nothing" value | pd.Series([1, None]) |
pd.NA |
pandas' missing marker for nullable types, printed <NA> |
Int64 column |
| NaT | "Not a Time": the missing value for dates | to_datetime(None) |
| Nullable type | A dtype that can hold real values and pd.NA |
Int64, boolean, string |
isna() |
True where a value is missing | log["temp"].isna() |
notna() |
True where a value is present | log.notna().sum() |
isnull() / notnull() |
Other names for isna() / notna() |
same results |
| Missing count | Number of blanks in a column | isna().sum() |
| Missing percentage | Share of blanks × 100 | isna().mean() * 100 |
dropna() |
Remove rows (or columns) with missing values | log.dropna() |
how |
"any" drops a row with any blank, "all" only if all are blank |
dropna(how="all") |
thresh |
Minimum number of real values a row needs to be kept | dropna(thresh=2) |
subset |
Columns dropna looks at |
dropna(subset=["cups"]) |
| Imputation | Filling a missing value with an estimate | median temperature |
fillna(value) |
Replace missing values with a value | fillna(20.0) |
| Mean | Sum ÷ count | 20.36 |
| Median | Middle value after sorting; robust to extremes | 20.0 |
| Mode | Most common value; mode() returns a Series |
mode()[0] → "UPI" |
| Index alignment | pandas matches values by index label, not position | fillna(series) |
ffill() |
Forward fill: copy the last known value forward | 24 → day 2 |
bfill() |
Backward fill: copy the next known value backward | 22.5 → day 2 |
interpolate() |
Estimate a blank from a straight line between neighbours | 23.25 |
| Group-wise imputation | Fill with a statistic of the row's own group | chai → chai median |
groupby |
Split rows into groups by a column's values | groupby("item") |
transform |
Compute per group, return one value per original row | transform("median") |
mask(cond) |
Replace values with NaN where cond is True |
hide low ratings |
| Missingness mechanism | The reason values are missing | MCAR, MAR, MNAR |
| MCAR | Missing completely at random: unrelated to any value | tablet freezes randomly |
| MAR | Missing at random: explained by other recorded columns | no rating on rush days |
| MNAR | Missing not at random: depends on the missing value itself | unhappy customers skip rating |
| Bias | A systematic error that pushes a result one way | 3.05 looks like 3.73 |
| Missingness indicator column | True/False column saved before filling, marking the blanks | rating_missing |
.copy() |
Make an independent copy of a DataFrame | df.dropna().copy() |
Summary
- A blank is unknown, not zero. pandas writes it as NaN, None,
<NA>or NaT;isna()finds them all. Never use== np.nan. - Measure with
isna().sum()andisna().mean() * 100. dropnaremoves any row with a blank by default; control it withhow,thresh,subset.- Impute with
fillna: median for numbers,mode()[0]for text, the group's median when groups differ;ffill/bfill/interpolatefor data in time order. Filling with 0 is usually wrong. - Ask why values are missing: MCAR (safe), MAR (use the related columns), MNAR (no formula fixes it).
- Flag before you fill, and record every decision in the cleaning log.
- Next episode: cleaning 2, duplicates and data types.