Missing values
Real data is rarely complete. A missing value shows up as NaN ("Not a Number") -- written as None when you build a DataFrame by hand, pandas converts it automatically:
data = {"x": [10, None, 20, None, 5]}
df = pd.DataFrame(data)
print(df)
Finding missing values
print(df["x"].isna()) # True/False per row
print(df["x"].isna().sum()) # how many are missing, as a count
Filling missing values
filled = df["x"].fillna(0)
print(filled.sum())
.fillna(value) replaces every missing entry in that column with value -- it doesn't change the original column unless you assign the result back to it (df["x"] = df["x"].fillna(0)).
Creating a new column
Any expression using existing columns can be assigned straight to a new column name:
df["score_x2"] = df["score"] * 2
This runs on every row at once -- no loop needed.
Why This Matters for Your Exams
Ignoring missing values instead of handling them deliberately is the most common real-world data analysis mistake -- a .sum() or .mean() over a column with NaNs silently skips them rather than erroring, which can quietly change your answer if you weren't expecting gaps in the data. Always check .isna().sum() before trusting a summary.
Try it yourself
Real-time practice is a paid add-on
Reading units and the practice quiz are free. Pay once to unlock running real code for DATASCI.

