The first 60 seconds with a new dataset
Whenever you load a new dataset, do this first.
1) Check shape
import pandas as pd
df = pd.read_csv("data/sales.csv")
print(df.shape) # (rows, columns)2) Preview rows
print(df.head())
print(df.tail())3) Random sample
Great for spotting weird values.
print(df.sample(5, random_state=42))4) Columns and dtypes
df.info()This tells you:
- Column names
- Non-null counts
- Dtypes
- Memory usage (helpful when data grows)
5) Descriptive stats
print(df.describe())For categorical columns:
print(df.describe(include=["object"]))Core sanity checks
Missing values per column
missing = df.isna().sum().sort_values(ascending=False)
print(missing)Duplicates
print("duplicate rows:", df.duplicated().sum())Value counts for a category
print(df["city"].value_counts(dropna=False).head(10))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
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
Exercise 1 – Check the Shape
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Summarize Numeric Columns
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Count Missing Values Per Column
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Check your understanding
What does df.shape return?
shape gives the tuple of the number of rows and columns.
Show answer
B — (rows, columns) — shape gives the tuple of the number of rows and columns.
Which call tells you column names, non-null counts, dtypes and memory usage?
info() reports that per-column summary. describe() reports statistics such as mean and quartiles.
Show answer
A — df.info() — info() reports that per-column summary. describe() reports statistics such as mean and quartiles.
Which expression shows the number of missing values per column, largest first?
isna() flags missing cells, sum() counts them per column and sort_values orders them.
Show answer
A — df.isna().sum().sort_values(ascending=False) — isna() flags missing cells, sum() counts them per column and sort_values orders them.
Why pass random_state=42 in df.sample(5, random_state=42)?
random_state seeds the sampling so the result is reproducible.
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).