Sub topic 2
Finding Missing Values with `info` and `describe`
Assume you know basic Python, have pandas installed as pd, and understand that a DataFrame is a table with labelled columns. This chapter focuses on checking missing values and summarizing numeric data before analysis.
Finding missing values with non-null counts
DataFrame.info() prints one line for each column. It shows the column name, how many values are not missing, and the column's data type.
import numpy as np
import pandas as pd
df = pd.DataFrame({
"name": ["Ana", "Ben", "Cleo", "Dev", "Eli"],
"age": [34, 28, np.nan, 45, 39],
"city": ["Lima", "Oslo", "Lima", "Pune", "Oslo"],
"salary": [52000, 48000, 61000, 75000, 58000],
})
df.info()
print(df.isna().sum())The DataFrame has five rows. The age column has four non-null values, so one value is missing. isna().sum() confirms the missing count directly.
A non-null count is useful because it can reveal both missing data and unexpected column types. For example, a numeric column stored as object may contain text that needs investigation.
Summarizing numeric columns with `describe`
df.describe() summarizes numeric columns and skips missing values. Its count is the number of non-null values.
| Statistic | Meaning |
|---|---|
| `count` | Non-null values |
| `mean` | Arithmetic average |
| `std` | Standard deviation, or spread |
| `min`, `max` | Smallest and largest values |
| `25%`, `50%`, `75%` | Quartiles |
print(df.describe())For age, count is 4 rather than 5. Compare the minimum, maximum, and quartiles with what the data should reasonably contain. A very large maximum can indicate an outlier or an entry error.
Choosing your own percentiles
Percentiles divide sorted values by position. The 50th percentile is the median. You can request different percentiles when the default quartiles do not answer your question.
print(df.describe(percentiles=[0.10, 0.90]))This adds the 10th and 90th percentiles. These values help describe the central range while reducing attention to extreme endpoints.
Exercise
In a five-row DataFrame, df["age"].describe() reports count as 4. What does that mean?
Show answer
One age value is missing or otherwise treated as null.