Skip to main content
← Python Study Guide

Unit 6 · Heavy

Data Science With Python

NumPy and pandas, and the shift from writing loops to describing operations on whole columns. Most of the difficulty is not syntax but knowing what a dataset actually contains before analysing it.

What a strong answer looks like

A strong Unit 6 answer inspects the data before computing on it, and states what was done about missing values rather than ignoring them.

Topics in this unit

1

Arrays and Vectorised Operations

Know

A NumPy array applies an operation across every element at once, which is both faster and clearer than an explicit loop.

Apply

Express element-wise work as an operation on the whole array.

Watch out

Writing a Python loop over an array, which discards the main reason for using one.

Study move

Convert a loop that doubles every element into a single vectorised expression.

2

DataFrames

Know

A DataFrame is a table with labelled rows and columns. Selecting by label and selecting by position are different operations with different methods.

Apply

Select columns by name and rows by condition, keeping the two selection styles distinct.

Watch out

Chained selection that returns a copy rather than a view, so an assignment appears to do nothing.

Study move

Filter rows by a condition and then modify a column, confirming the change actually persisted.

3

Cleaning and Missing Data

Know

Real data has gaps, duplicates, and wrong types. Every choice about them changes the result, so each must be deliberate and recorded.

Apply

Inspect the shape, the types, and the count of missing values before any analysis.

Watch out

Dropping rows with missing values silently, which can remove exactly the group you were studying.

Study move

Take a dataset with gaps, report the missing count per column, and justify one handling choice.

4

Grouping and Summarising

Know

Grouping splits rows by a key, applies an aggregation to each group, and combines the results into a new table.

Apply

Use grouping to answer per-category questions rather than looping over categories manually.

Watch out

Reporting an average over groups of very different sizes without saying so, which hides the imbalance.

Study move

Group a dataset by one column, compute two aggregations, and report the group sizes alongside.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Inspecting a dataset before computing on it
  • Making missing-value handling explicit
  • Reporting group sizes alongside group averages

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Library choice. Some sections use only pandas; others introduce NumPy first.
  • Statistical depth. Formal statistics is covered lightly and belongs to a statistics course.

Mastery checklist

  • Write a vectorised operation instead of a loop.
  • Select DataFrame rows by condition and columns by name.
  • Report missing values per column.
  • Group, aggregate, and report group sizes.

Check yourself

  • Why is a loop over a NumPy array usually the wrong approach?
  • Why can an assignment after chained selection silently fail?
  • What can go wrong when rows with missing values are dropped?

Modeling drill

Take a dataset with missing values and uneven categories, produce a per-category summary, and state explicitly what you did about the gaps.

NumPy arrayVectorisedDataFrameLabel selectionMissing valueGroup byAggregation