November 3, 2026 · krey

Python for Data Analysis: From Fundamentals to Reliable Notebooks

Python becomes useful for data work when you can move beyond syntax and build a small, reliable workflow. The goal is to write code that another person can read, run and verify.

Core Python skills

Practise functions with clear inputs and outputs, loops and comprehensions, dictionaries and sets, exceptions, modules and file paths. Learn to avoid hidden state in notebooks: restart the kernel, run cells in order and make the required imports explicit.

def missing_rate(values):
    missing = sum(value is None for value in values)
    return missing / len(values) if values else 0

A small function like this is easy to test and explain. Meaningful names and a clear edge-case policy matter more than clever one-liners.

Use arrays and tables deliberately

NumPy arrays are designed for numerical operations over homogeneous data, while Pandas DataFrames represent labelled tabular data. Understand the shape, index and data type of an object before applying a transformation. After filtering or joining, check row counts and key uniqueness.

Clean before you visualise

Inspect missing values, duplicated records, impossible ranges and inconsistent categories. Do not silently convert errors into zeros. Record whether a value was missing because it was not collected, not applicable, or lost during ingestion; those cases may require different treatment.

Write analysis that answers questions

A good notebook has a narrative: question, data, checks, analysis, result and limitations. Each chart should have a title, labelled axes and a reason for existing. Avoid producing a wall of plots without explaining which pattern matters.

Turn exploration into reusable code

When a notebook stabilises, move repeated transformations into functions or modules, add assertions for expected columns and write a short README. Keep exploratory decisions visible in the report, but make the final path reproducible from a clean environment.

References

Make notebooks reproducible

Start each notebook with its purpose, input assumptions and expected output. Use a small configuration section for file paths, set a random seed where a library supports it, and avoid relying on variables created in an earlier hidden cell. Restart the kernel and run all cells before publishing. If a long computation is required, explain how to reproduce it without committing a large generated file.

Validate transformations

After filtering, joining or aggregating, inspect the row count and a few representative records. Before and after a join, ask whether the relationship is one-to-one, one-to-many or many-to-many. After a group operation, confirm that totals reconcile with the source. These checks catch silent duplication and unexpected missing records earlier than a final chart does.

summary = (
    orders.groupby("customer_id", as_index=False)
    .agg(order_count=("order_id", "nunique"),
         revenue=("amount", "sum"))
)
assert summary["customer_id"].is_unique

From exploration to reusable code

Not every exploratory line belongs in a package, but repeated cleaning and feature logic should move into named functions. Give those functions small inputs and predictable outputs. Add tests for empty data, missing values, unexpected categories and duplicate identifiers. This makes later model work faster because you can improve the analysis without repeatedly debugging the same preparation steps.