Lingnan University · FACULTY OF COMPUTER SCIENCE

CDT501 Chap.8 NumPy, pandas and Visualisation

- one subject, every graph, every model, every mark
5 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 8 of 8 · CDT501

NumPy, pandas and Visualisation

Keep the table visible behind the picture

This chapter compares numerical arrays with labelled DataFrames, then builds a load, inspect, transform and visualise pipeline. Groupby is treated as split, apply and combine, with an explicit change in the unit of observation. Chart choice follows the comparison, while conversion failures, label alignment and shape mismatches remain visible as data findings.

In this chapter

What this chapter covers

  • 01

    NumPy arrays and shapes

  • 02

    Pandas DataFrames and types

  • 03

    Groupby split-apply-combine

  • 04

    Chart choice and visual encodings

  • 05

    Reproducible analysis pipelines

Worked example · free

Repair a numeric column stored as text

Q [8 marks]. Currency symbols make a sales column textual. Design a checkable conversion and grouped summary. Marks shown for this pipeline guide AskSia practice and are not official University criteria.
The arrows show split, apply and combine.The arrows show split, apply and combine. Rows are partitioned by a grouping key, the same summary is computed for each group, and the results return as a labelled table.A grouped summary preserves the route from rows to resultrowsgroup Agroup Bapplysame summarycombined tableone row per groupsplitcombine
The arrows show split, apply and combine. Rows are partitioned by a grouping key, the same summary is computed for each group, and the results return as a labelled table.
  • 3Inspect type and original invalid values.
  • 2Apply documented cleaning and conversion.
  • 3Verify one group before plotting.
Preserve the original column, remove only the documented currency formatting and convert in a way that reports invalid rows. Review those rows rather than silently filling them. Group the validated numeric column by the intended key, calculate the stated statistic, and compare one group's result with a manual subset before plotting.
Sia tip — Inspect the grouped table before the chart.
Glossary

Key terms

Array Shape
The dimensions describing how numerical values are organised in an array.
Aggregation
A calculation that reduces multiple observations to a summary such as count, sum or mean.
Missing Value
A marker indicating that an expected observation is absent or unavailable under a stated rule.
Visual Encoding
The mapping from data values to position, length, colour or another visible property.
Unit Of Observation
The entity represented by one row at a particular stage of an analysis.
FAQ

NumPy, pandas and Visualisation FAQ

What is the practical difference between an array and a DataFrame?

A NumPy array offers regular numerical structure and shape-based operations, while a pandas DataFrame adds labelled rows and columns and can hold different column types. Converting between them may lose labels or alter dimensions, so inspect both shape and meaning after each conversion rather than relying on similar printed output.

What does groupby change about the data?

Groupby partitions rows using one or more keys, applies a summary to each partition and combines the results into a new table. The unit of observation usually changes from an original row, such as a transaction, to a group, such as a region. Name aggregated columns and keep the grouping key visible.

How do I choose a chart for grouped results?

Start with the comparison. Bars suit magnitudes across discrete categories, lines emphasise ordered change and scatter plots show paired numerical observations. Name the axes, units and aggregation, then verify every visual mark against the grouped table. A chart describes patterns but does not by itself establish causation.

Why should I record row counts through a data pipeline?

Row counts provide a compact audit trail for operations that can remove, duplicate or combine observations. Record the count after loading, cleaning, filtering, joining and grouping, and explain each expected change. An unexpected drop may reveal a filter with the wrong condition or unmatched join keys; an increase may indicate duplicate keys or a many-to-many merge.

Counts alone do not prove correctness, so pair them with column checks, missing-value summaries and a few known records. After aggregation, also state the new unit of observation because fewer rows may be exactly the intended result. Keeping these checkpoints makes it possible to locate the first stage where the data diverged instead of debugging only the final chart.

Study strategy

Assessment move

Use a small CSV whose correct summary you can calculate by hand. Record shape, labels, types and missingness before cleaning. Keep each pipeline stage in a descriptive variable and count rows after filtering. Group once, verify one category manually, then write an encoding sentence before plotting. Restart and run the complete pipeline from original inputs to expose hidden notebook state.

Preserve the raw columns before conversion so every cleaning decision remains auditable. Introduce one currency-formatted value, one empty value and one invalid word in a numeric-looking column. Convert in a way that identifies failures, inspect their original text and decide whether each represents formatting, missingness or corruption. Report the count and effect of exclusions rather than silently replacing them.

Compare an array and a one-column DataFrame containing the same numbers; record their shapes, labels and the operations each supports. Join two tiny tables with their key order deliberately reversed to show why matching row counts do not prove alignment. Before grouping, state what one row represents. After grouping, state the new unit and give aggregated columns names containing the statistic, such as mean amount.

Manually calculate one group's value and reconcile it with pandas before drawing anything. Choose a chart from the comparison: bars for discrete magnitudes, a line for ordered change or a scatter plot for paired measurements. Write an encoding sentence naming what each mark and axis means, include units and verify every visual value against the grouped table.

Add group counts beside averages and describe the pattern without turning association into cause. Finally restart the runtime, load the original file and regenerate the table and chart in order. Compare the new image with the version intended for submission so a stale export cannot survive a pipeline change.

Working through NumPy, pandas and Visualisation in CDT501? Sia is AskSia’s AI Computer Science tutor — ask any CDT501 NumPy, pandas and Visualisation question and get a clear, step-by-step explanation grounded in how CDT501 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 9 of your Lingnan University subjects - and 1,000+ Bibles across every Australian university.
Sia - your CDT501 tutor, unlimited, worked the way the exam marks it
The full 4-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
CDT501 · Computer Systems and Programming Basics - independent study guide on the AskSia Library. More Lingnan University subjects · Microeconomics across all universities