The advantages of code over manual tools, the structure of the Python data stack, and setting up a local or cloud environment.
3 units · Distance education (asynchronous online)
This deck is designed for asynchronous viewing: dark "pause" slides mark suitable stopping points between parts. Part C is easiest with a second screen or phone displaying these slides during typing.
≈3 hours of material, matching the course's 3 weekly contact hours. The pauses between parts are intended to be used.
What code provides that spreadsheets and point-and-click tools cannot.
An overview of NumPy, pandas, matplotlib and related libraries, and the role of each.
A working environment, either installed locally or run in the cloud without installation.
Goal for the week: run a first notebook cell on real data before next Monday.
The material is self-paced, but the Week 1 setup checkpoint is fixed because all later work depends on it.
Memorisation is not required at this stage. Each term is explained again on the slide where it is first used, and all are collected in a glossary near the end.
A file of code — written instructions — that Python runs from the top line to the bottom.
e.g. a file called clean_survey.py
A bundle of ready-made code written by others and loaded into a new program.
e.g. pandas (tables), NumPy (numbers), matplotlib (charts)
The line that loads a library so that the code can use it.
e.g. import pandas as pd — load pandas, call it pd for short
A document of boxes that mix text and runnable code. Jupyter and Colab show notebooks.
e.g. week01_hello_data.ipynb
One box in a notebook. Shift+Enter runs it; the result appears underneath.
e.g. a cell containing 1 + 1 shows 2
The Python program running behind a notebook. It retains everything run so far.
e.g. “Restart kernel” wipes that memory clean
A name that holds a value (a piece of data), like a labelled box.
e.g. price = 100 puts 100 in a box labelled price
A named piece of work. It is called by writing its name and brackets; inputs go inside the brackets.
e.g. print("hi") calls the function print
Python stopping because it cannot carry out a line. Errors are normal, expected and fixable.
e.g. a misspelt name gives a NameError
The report printed with an error. Read the last line first: it names the problem.
e.g. NameError: name 'pirce' is not defined
In October 2020, Public Health England lost track of nearly 16,000 positive COVID-19 cases because an old Excel format truncated rows beyond its limit without any warning.
Spreadsheets remain suitable for small tables. The problem is that invisible, unrepeatable data handling fails silently at scale.
A month later, no one, including the analyst, can state exactly which cells were edited, filtered or pasted.
Each new monthly file requires the same 40 clicks, and each repetition can introduce a new mistake.
Millions of rows, nested JSON, joins across ten files and statistical models exceed what a spreadsheet grid can handle.
Reinhart & Rogoff's influential 2010 paper "Growth in a Time of Debt" argued growth collapses when public debt passes 90% of GDP — and was cited to justify austerity worldwide. In 2013, graduate student Thomas Herndon attempted to replicate it and found, among other issues, an Excel formula that omitted five countries.
The error surfaced only because Herndon requested the actual spreadsheet and re-ran the analysis. No script existed to audit; the analysis existed only as cell selections.
Fernando Pérez builds a better interactive Python prompt.
Code, output and text together on one page in the browser.
The notebook becomes its own project, named for Julia, Python and R.
Free Jupyter notebooks that run on Google’s computers.
Colab, used in this course, is a Jupyter notebook hosted by Google: nothing to install.
A notebook is a document that mixes runnable code cells with ordinary text and the results the code produced.
public notebooks on GitHub by January 2021, up from 200,000 in 2015.
The 2017 ACM Software System Award, for software with a lasting influence.
downloads of ipykernel, the part that runs Python inside a notebook, in September 2026.
A notebook is the usual way to share an analysis: the code, its output and the explanation travel in one file.
pip install of a package, by a person or by an automated serverSourceNotebook counts and award: Wikipedia: Project Jupyter; downloads: pypistats.org, without mirrors, retrieved 11 Oct 2026
Three advantages: reproducibility, scale, automation.
Data analysis by clicking through a spreadsheet is assumed. This part shows what is gained when those clicks are written down as code instead.
Code is written instructions for the computer. A script is a file of code that runs from top to bottom: a complete, ordered, re-runnable record of every step from raw file to final figure. Anyone who runs it later, including its author, obtains exactly the same result.
Writing this is not expected yet. Analogy: a script is a recipe card; each line is one step, in order, and anyone can follow it again.
# The whole analysis…a comment: a note for humans. Python ignores everything after #import pandas as pdload the pandas library and call it pd for shortdf = pd.read_csv(…)read the CSV file into a table and store it under the name dfdf.dropna(subset=["program"])throw away rows where the program column is blankdf.groupby("program").size()count how many rows there are for each programsummary.to_csv(…)save those counts to a new file; print shows them on screen too“Obtaining consistent computational results using the same input data, computational steps, methods, code, and conditions of analysis.”
“Obtaining consistent results across studies aimed at answering the same scientific question, each of which has obtained its own data.”
| Applied to the script on the previous slide | Reproducible? |
|---|---|
Run it again tomorrow on the same enrollment_2026.csv | yes: the same counts, every time |
| Repeat the filtering by hand in a spreadsheet | only if every click is remembered |
| Run it on another university’s enrolment file | a replication: new data, same question |
Source: National Academies of Sciences, Engineering, and Medicine (2019), Reproducibility and Replicability in Science, ch. 3.
| Task | By hand | With a script |
|---|---|---|
| Clean 1 survey file | 20 minutes of careful clicking | Write once: ~15 lines |
| Clean 300 survey files | Weeks, with drifting rules | The same 15 lines in a loop |
| Redo everything after a data fix | Start over, with no guarantee of consistency | Re-run: one command |
| Monthly report, every month | A recurring manual task | Scheduled job, runs unattended |
Effort moves from every time to one time. This trade is the main economic argument for this course. (A loop tells the computer to repeat the same lines once per item — here, once per file. A scheduled job is a script the computer starts by itself at a set time.)
The first script takes longer than the first manual pass. The time saving begins at the second repetition.
It does exactly what was written, not what was intended. Every bug (a mistake that makes code do the wrong thing) is a gap between the two, usually a small and findable one.
Professionals see error messages constantly and read them as directions for a fix, not as failure.
Any analysis, however large, is composed of small steps: load, filter, group, plot. A confusing step can be split further.
The first three weeks are typically slow and mechanical while typing becomes familiar. Speed usually increases around Week 5, with pandas.
Tolerance for frequent, correctable mistakes, several times per hour.
Import = get the data into Python. Tidy = arrange it so each row is one thing and each column one measurement. Transform = filter, compute and summarise. Visualize = draw it. Model = fit a statistical model. Communicate = explain the findings to others.
Adapted from Wickham & Grolemund's R for Data Science — the workflow is language-agnostic; this course follows it in Python.
Import/tidy → Weeks 5–7 · visualize → Week 8 · every stage → the Week 12 project.
A colleague presents an analysis: a formatted Excel workbook in which they manually filtered, copied cleaned rows to a new sheet, and built a chart. The numbers are correct. From a programming-for-data-science standpoint, what is the core problem?
Choose an answer, then click and hold (or tap) to show the answer
C — it is a reproducibility problem, not a correctness problem.
The work may be correct today, but the manual steps are invisible: they cannot be audited (Reinhart–Rogoff), re-run when data updates, or scaled to the next 300 files. The result is not wrong; it is unrepeatable.
A suitable place to stop or take a five-minute break. Part B surveys the Python libraries used throughout the semester.
One language, with a division of labor among libraries.
Part A explained why code is written. This part shows what it is written with: one language, Python, plus a small set of libraries that each do one job.
| Language | Strengths | Role in this course |
|---|---|---|
| Python | Readable, large ecosystem, general-purpose (web, automation, ML) | Course language; one language covers the whole workflow |
| R | Statistics-oriented, strong plotting (ggplot2) | Suitable to learn later if a field favors it |
| SQL | The standard language of databases | Complementary; introduced in Week 9 |
| Julia | Speed for numerical computing | Growing, with a smaller ecosystem |
A programming language is a strict, written vocabulary for giving a computer instructions; its ecosystem is all the libraries and tools built for it. Skills transfer: the concepts taught here — thinking in tables, operating on whole columns at once (vectorized operations), tidy workflows — carry to any of these languages.
The course assumes none. Weeks 2–4 build the language from the ground up.
NumPy = fast arrays. pandas = labeled tables. About 80% of course code uses them. “Data science” is not one install; it is assembled from these parts, week by week.
A code block with a ▶ Run / Edit button runs in the browser, and the code can be changed and run again. Nothing needs installing for this; the first run downloads Python into the page, which takes 10 to 20 seconds.
The grey lines under a block are what the lecture laptop printed when it ran that exact code. Running it in the browser prints the same.
NumPy's array is a row of numbers, all of the same kind, that NumPy can do maths on in one go. It replaces the loop: the operation is written once and applies to every element (every number in the array), very fast. This idea — vectorization, one operation applied to a whole array — is the largest conceptual change from ordinary programming.
An Excel formula typed once that fills the whole column without being dragged down.
The goal this week is only to recognize the shape of the code. Week 5 builds fluency.
rain = np.array([…])make an array of six rainfall numbers and name it rainrain * 0.1multiply every number by 0.1 at once — no loop neededrain.mean()the average of all six: about 131.6 mmrain > 100ask “over 100?” of each number; each answer is True (yes) or False (no)rain[rain > 100]keep only the numbers where the answer was TrueOne comparison, rain > 100, asks a question of every month at once.
100 to 200. Which months are left?Result on the lecture laptop (select to reveal)
3 wet months: 156.3, 301.9 and 288.0 mm. With 200: 301.9 and 288.0.
pandas puts labels on NumPy's speed. Its table is called a DataFrame: rows and named columns, like a spreadsheet controlled with code. Questions answered by clicking in Excel become one readable line each.
A CSV file (“comma-separated values”) is a plain-text table: one row per line, commas between the columns. Excel can save one; pandas can read one.
Weeks 6–7 cover only pandas. Working data scientists spend most of their time in it.
df = pd.read_csv("…csv")read the CSV file into a DataFrame called dfdf.groupby("barangay")["no_show"].mean()for each barangay, the average of the no_show column — a pivot table in one linedf[df["distance_km"] > 4]keep only the rows where distance is over 4 km.sort_values("age")then put those rows in order of ageThe made-up clinic table has 8 patients in 3 barangays; no_show is 1 for a missed appointment.
"no_show" to "age". What does the line answer now?Result on the lecture laptop (select to reveal)
Talamban: 0.667, two of its three patients. With "age" the line gives the mean age per barangay: Lahug 47.5, Mabolo about 41.7, Talamban about 44.0.
matplotlib draws; seaborn (built on top) produces well-formatted statistical plots by default. Every chart is code, so every chart is reproducible and revisable.
By Week 8, a figure is treated like a paragraph: drafted, revised and defended.
import matplotlib.pyplot as pltload matplotlib’s drawing tools, nicknamed pltmonthly = df.groupby("month")…sum()total visits per month, from a table df loaded earliermonthly.plot(kind="bar")draw those totals as a bar chartplt.title(…) / plt.show()add a title, then display the finished chartA CSV holds 200,000 e-wallet transactions, and the task is the average amount per province. Which layer of the stack does most of the work?
Choose an answer, then click and hold (or tap) to show the answer
C — this is a typical pandas task: labeled table, grouped summary.
A works but is slow to write and easy to get wrong; B rebuilds what pandas already provides; D confuses drawing with computing. Matching the task to the layer is a learnable part of fluency.
The next part is hands-on and requires a laptop and about 1 hour. It ends with a working environment, which is this week's deliverable.
Two setup options; one is chosen this week.
Part B showed what the tools do. This part installs them on a personal computer or runs them in the browser, and ends with a first line of code and a first error message.
Both paths run every notebook in this course. Switching is possible at any time because the code is identical.
If setup fails for more than 30 minutes, switch to Colab, post in the forum and continue. An installer problem should not delay the week.
jupyter lab and press Enterlocalhost:88881 + 1 in the cell, press Shift+Enter2 confirms that the installation worksjupyter lablocalhostAnaconda needs ~5 GB free. With less space, use Colab this week and install later. Common problems (antivirus prompts, “command not found”) are in the setup guide on the course page.
1 + 1 and press Shift+EnterColab is a professional tool, not a simplified substitute. A session is the Python process currently running behind a notebook: when it disconnects, its variables are lost, but the saved notebook and files remain.
Every course notebook has an "Open in Colab" badge that opens a running copy from the course page in one click.
A notebook is a sequence of cells (boxes of text or code) run by a live kernel — the Python program behind the page, which remembers everything run so far. To execute or run a cell means to make Python carry it out.
Running cells out of order. The kernel's memory follows execution order, not page order; the fix is "Restart & Run All."
Formatted text, headings and math that explain why. Markdown is a
plain-text way to format text: # Title becomes a heading.
Python that runs on Shift+Enter; the result prints directly below.
The Python process holding the variables. Restarting it clears all of them, which is sometimes necessary.
A variable is a name that holds a value (a piece of data, such as the number 100). Running these three cells in the order 1 → 3 → 2 → 3 makes the "same notebook" give two different answers. The kernel records only what ran, and when.
Before trusting or submitting a notebook: Kernel → Restart & Run All. If it errors or changes, its displayed results were not reproducible.
price = 100assignment: put the value 100 in a box labelled price. = means “store”, not “equals”price = price * 2take what is in price now, double it, store it back (* means multiply)print(price)call the print function: show the value on screen — 200 after one run of cell 2, 400 after twoHere the three cells run as one script, top to bottom, with cell 2 repeated: what an accidental second run does.
print(price) shows.Result on the lecture laptop (select to reveal)
400: the second run doubles 200 again. Without the repeat it prints 200, the result the page appears to show.
| Mode | What it is | Best for |
|---|---|---|
| Notebook (.ipynb) | Cells + narrative + inline output | Exploration, teaching, reports; the course default |
| Script (.py) | Plain file run top to bottom | Automation, reusable pipelines (Week 11) |
| REPL | Interactive prompt, one line at a time | Quick checks, such as the value a function returns |
Professionals use all three daily. The course starts with notebooks because
seeing each step's output speeds learning. REPL stands for
Read–Evaluate–Print Loop: one line is typed and its answer appears at once. The ending of a
file name (.ipynb, .py) is its extension: it says what kind
of file it is.
Explore in a notebook; when it works and must run repeatedly, promote it to a script.
Memorizing syntax is not required. This week's focus is the shape of the work: load, look, count.
"Import pandas. Read the CSV into a table called df. Show the first rows. Count
by region." Python code is designed to be read as sentences.
The text in quotes, "psa_population.csv",
is a file path: the address of a file on the computer. A bare file
name means “in the same folder as this notebook”; a path like
data/psa_population.csv means “inside the data folder”.
df = pd.read_csv("psa_population.csv")call pandas’ read_csv function; the table it gives back is stored in dfdf.head(3)the dot means “do this to df”: show its first 3 rows (5 without a number), to check what was loadeddf.shapethe table’s size as a pair: (number of rows, number of columns)df["region"].value_counts()take the region column and count how many rows each region hasAn error is Python stopping because it cannot do what a line asks. The traceback is the structured report it prints. The last line is read first: error type, then message. The lines above show where the error occurred.
NameError — a name was used before being defined, or was misspeltFileNotFoundError — wrong filename or wrong folderSyntaxError — Python could not parse the lineNameError: …the error type (NameError = a name Python does not know) and the message: pirce was never definedFile "cell 4", line 1where it happened: cell 4, line 1 — the line to inspect^^^^^points at the exact part of the line Python could not handle>>> print(pirce)the line that was run (>>> is the prompt where code is typed). The fix: spell it priceThis block fails on purpose. Its last line names the error and suggests a fix.
Result on the lecture laptop (select to reveal)
NameError: name 'pirce' is not defined. Did you mean: 'price'? With print(price) it prints 100.
The last line of the traceback plus the function's official documentation solves most beginner problems in under five minutes.
Most errors have been encountered and answered before. If 15 minutes of searching fails, post to the course forum: the error, the code, and what was tried.
Allowed for explaining errors and concepts. For graded exercises, students must be able to explain every submitted line and disclose any AI assistance. Details in the syllabus.
Each step builds a skill that employers test for: reading errors, searching effectively and asking questions.
A forum post with a minimal reproducible example — the shortest code that still shows the problem — is often solved in the process of writing it. (Docs, short for documentation, is the official manual for a language or library.)
Twelve weeks from no experience to a working pipeline.
Part C produced a working setup and a first error. This part explains how the rest of the course runs, and what to complete before next week.
| Weeks | Theme | Topics |
|---|---|---|
| 1–4 | Python foundations | This intro · types & functions · data structures & files · OOP and errors |
| 5–7 | NumPy & pandas | Arrays · loading & cleaning tables · grouping, merging, reshaping |
| 8–10 | Visualization & sources | matplotlib & seaborn · files, SQL & APIs · text & regex |
| 11–12 | Workflows & project | Git, environments & debugging · integrative project presentations |
Each week: a short lecture deck like this one, a code-along notebook, and one graded exercise. Unfamiliar names in the table are explained in the week they are introduced.
A small end-to-end pipeline (a script that takes raw data all the way to a result) on a dataset from the student’s own field — scoped in Week 8, presented in Week 12.
Materials are released Monday; exercises are due Sunday night. Study hours within the week are flexible.
Questions go to the course forum so everyone benefits; expect instructor replies within one working day.
After 30+ minutes without progress, post what was tried. Debugging in public is a professional skill.
Course details: 3 units, graded (GRD), no prerequisites. The course is repeatable for credit per the catalog.
Plan for ~3 hours of contact material plus 3–4 hours of practice weekly. Programming is learned through practice.
All new terms from this week, one line each, for reference in later weeks.
clean.py# that Python ignores; it is for human readersprice = 100print("hi")data/grades.csvimport pandas as pdThe Week 1 lab runs in the browser from the course page. Replace each
____, press ▶ Run to see the output, then
Check. It borrows a few ideas from the next two weeks — the lab explains
each one where it is used, and later weeks cover them fully.
Mastery of these terms is not expected yet. The goal this week is to press Run, read the output, and fix one small thing at a time.
[28, 31, 29] (Week 3)"Ana" (Week 2)f that fills in values from { }One goal: a working environment with proof.
Install Anaconda (Path A) or sign in to Google Colab (Path B) — links on the course page.
Download week01_hello_data.ipynb from the course page and run every cell
top-to-bottom.
Upload the executed notebook (every cell run, so each result shows underneath it) to the submission portal, and post an introduction in the forum: field, data of interest, and Python experience (none is acceptable).
A script is a record that re-runs; clicks leave no lasting record.
Python underneath, NumPy/pandas as the core libraries, Jupyter on top as the workspace.
One working environment, local or cloud, demonstrated with an executed notebook.
All of Weeks 2–12 assumes the Week 1 checkpoint is complete, so the hour is best spent now.
Forum first, the 30-minute rule, and Colab as a fallback in any browser.
McKinney, Python for Data Analysis (wesmckinney.com/book) — by pandas' creator. · VanderPlas, Python Data Science Handbook (jakevdp.github.io/PythonDataScienceHandbook).
docs.python.org (the official tutorial) · pandas.pydata.org/docs · Colab's own intro notebooks at colab.research.google.com.
All links are collected on the course page.
For questions about a function, consult its official docs before other web sources; this is usually faster.
Types, control flow and functions: the grammar of every Python script. A working environment is required.
DS 208 · Programming for Data Science