Python module
Foundations · Module 03
Python
Virtualenvs, scripts, files as data, pandas, and loading Postgres from Python. Practice only on your machine.
Beginner17 lessons~10 hours plus a demo
Data jobs are Python scripts in a virtualenv: read files, call an API, shape a DataFrame, write rows to Postgres. Notebooks are files you inspect — not the source of truth for a pipeline. This module teaches that spine after Linux and Docker.
You will install Python, use venv and pip, work with CSV and JSON, touch NumPy and pandas, talk to Postgres with psycopg, then generate random retail orders and load them. The site never runs Python for you.
Start here
Finish Linux and DockerGetting Started first so you have a terminal, ~/dcubes, and Compose. Then do this module’s Getting Started — we create ~/dcubes/python-lab and check python3.
On-ramp
ReadyYour Python practice environment
Install Python 3.11+ on Windows, macOS, or Linux. This site never runs Python — you will.
40 min
Lesson 1
ReadyWhy Python for data and AI
Where Python shows up in data work, and which skills this module will teach.
20 min
Lesson 2
ReadyREPL and scripts
Use the interactive interpreter for tiny checks, and .py files for real work.
25 min
Lesson 3
ReadyVirtualenvs and pip
Isolate project dependencies with venv, install packages, and freeze requirements.
30 min
Lesson 4
ReadyTypes and collections
Strings, numbers, booleans, and list/dict/tuple/set — the shapes data rows take in Python.
30 min
Lesson 5
ReadyControl flow and functions
if/for/while and small def helpers — the spine of every data script.
35 min
Lesson 6
ReadyErrors and logging
Catch failures on purpose and log what jobs did — print is not enough.
30 min
Lesson 7
ReadyPaths and text files
Use pathlib to build paths, read and write text, and keep a clean lab layout.
30 min
Lesson 8
ReadyCSV and JSON
Read and write tabular CSV and nested JSON with the standard library.
35 min
Lesson 9
ReadyHTTP and simple APIs
Fetch JSON over HTTP with httpx, check status codes, and keep secrets in the environment.
35 min
Lesson 10
ReadyNumPy basics
ndarrays, shape, dtype, and vectorized operations — the array mental model under pandas and ML.
35 min
Lesson 11
ReadyDataFrames
Load CSV into pandas, inspect dtypes, filter rows, and handle simple missing values.
40 min
Lesson 12
ReadyGroup, join, write
groupby aggregates, simple merges, and writing results back to CSV.
40 min
Lesson 13
ReadyPostgres from Python
Connect with psycopg, run parameterized SQL, and insert rows into a Compose Postgres.
45 min
Lesson 14
ReadyDataFrames and Postgres
Move data between pandas and PostgreSQL with psycopg — load from a DataFrame, read query results back.
40 min
Lesson 15
ReadyScripts, modules, and typing
Import your own code, use if __name__, type hints, and a clean requirements.txt.
35 min
Lesson 16
ReadyNotebooks as files
Run Jupyter in a venv, understand that .ipynb is JSON, and keep scripts as the source of truth.
35 min