Data Inspection (head, tail, info, describe)
The first 60 seconds with a new dataset
Section titled “The first 60 seconds with a new dataset”Whenever you load a new dataset, do this first.
1) Check shape
Section titled “1) Check shape”import pandas as pd
df = pd.read_csv("data/sales.csv")
print(df.shape) # (rows, columns)2) Preview rows
Section titled “2) Preview rows”print(df.head())
print(df.tail())3) Random sample
Section titled “3) Random sample”Great for spotting weird values.
print(df.sample(5, random_state=42))4) Columns and dtypes
Section titled “4) Columns and dtypes”df.info()This tells you:
- Column names
- Non-null counts
- Dtypes
- Memory usage (helpful when data grows)
5) Descriptive stats
Section titled “5) Descriptive stats”print(df.describe())For categorical columns:
print(df.describe(include=["object"]))Core sanity checks
Section titled “Core sanity checks”Missing values per column
Section titled “Missing values per column”missing = df.isna().sum().sort_values(ascending=False)
print(missing)Duplicates
Section titled “Duplicates”print("duplicate rows:", df.duplicated().sum())Value counts for a category
Section titled “Value counts for a category”print(df["city"].value_counts(dropna=False).head(10))Tip: create an inspection helper
Section titled “Tip: create an inspection helper”import pandas as pd
def inspect(df: pd.DataFrame, n: int = 5) -> None:
print("shape:", df.shape)
print("columns:", list(df.columns))
print("\nhead:")
print(df.head(n))
print("\nmissing:")
print(df.isna().sum())
# inspect(df)Visualize it
Section titled “Visualize it”flowchart LR A["df.shape"] --> B["df.head() / df.tail()"] B --> C["df.info()"] C --> D["df.describe()"] D --> E["df.isna().sum()"]
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Check the Shape
Section titled “Exercise 1 – Check the Shape”Exercise 2 – Summarize Numeric Columns
Section titled “Exercise 2 – Summarize Numeric Columns”Exercise 3 – Count Missing Values Per Column
Section titled “Exercise 3 – Count Missing Values Per Column”Once you know what’s in your data, learn how to slice into it precisely with Indexing and Selecting Data (loc, iloc).
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading