Python Central HubSign in

Data Analytics with Python / Phase 3: Data Manipulation with Pandas

Data Inspection (head, tail, info, describe)

Learn fast ways to inspect a dataset in Pandas using head/tail/sample/info/describe and basic sanity checks.

The first 60 seconds with a new dataset

Whenever you load a new dataset, do this first.

1) Check shape

Python
import pandas as pd
 
df = pd.read_csv("data/sales.csv")
print(df.shape)  # (rows, columns)

2) Preview rows

Python
print(df.head())
print(df.tail())

3) Random sample

Great for spotting weird values.

Python
print(df.sample(5, random_state=42))

4) Columns and dtypes

Python
df.info()

This tells you:

  • Column names
  • Non-null counts
  • Dtypes
  • Memory usage (helpful when data grows)

5) Descriptive stats

Python
print(df.describe())

For categorical columns:

Python
print(df.describe(include=["object"]))

Core sanity checks

Missing values per column

Python
missing = df.isna().sum().sort_values(ascending=False)
print(missing)

Duplicates

Python
print("duplicate rows:", df.duplicated().sum())

Value counts for a category

Python
print(df["city"].value_counts(dropna=False).head(10))

Tip: create an inspection helper

Python
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

diagram The 60-second inspection routine mermaid
A repeatable sequence for getting oriented with any new dataset.

🧪 Try It Yourself

Exercise 1 – Check the Shape

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Summarize Numeric Columns

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Count Missing Values Per Column

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Check your understanding

quizCheck yourself
  1. What does df.shape return?

    Show answer

    B — (rows, columns) — shape gives the tuple of the number of rows and columns.

  2. Which call tells you column names, non-null counts, dtypes and memory usage?

    Show answer

    A — df.info() — info() reports that per-column summary. describe() reports statistics such as mean and quartiles.

  3. Which expression shows the number of missing values per column, largest first?

    Show answer

    A — df.isna().sum().sort_values(ascending=False) — isna() flags missing cells, sum() counts them per column and sort_values orders them.

  4. Why pass random_state=42 in df.sample(5, random_state=42)?

    Show answer

    A — To get the same sampled rows each time — random_state seeds the sampling so the result is reproducible.

Next

Once you know what's in your data, learn how to slice into it precisely with Indexing and Selecting Data (loc, iloc).

Was this page helpful?

Let us know how we did