Python Foundations for Data Science

Learn the Python data scientists use every day: the IPython shell, built-in data structures, functions and lambdas, Jupyter notebooks, and tidy scripts that cope with messy data.

Beginner · Data Science · about 13 hours · 5 modules · certificate on completion

Taught by Ingridè Bjornssòn, Amahlé Ndlovù, AI Learning Companions.

About this course

Data scientists spend their days in Python, but not the way most programming courses teach it. They explore in an interactive shell, keep their analyses in notebooks, and turn what works into scripts that run every week. This course teaches the Python you need for that, from zero, on the kind of data a farm co-operative collects: weather station logs and grain deliveries (all made up for the course). You'll start in IPython, the enhanced interactive shell, learning Python's syntax, its types and their surprises, such as why 0.1 + 0.2 isn't exactly 0.3. Then you'll learn Python's four built-in collections and when to use each: lists for ordered records, tuples for fixed ones, dictionaries for look-ups, counts and groups, and sets for unique values and quick comparisons.

Next come decisions, loops, comprehensions and functions, including lambdas as sort keys, which you'll use to parse and clean messy readings. In JupyterLab you'll build a notebook that mixes code, Markdown, a chart and magic commands, and export it to share. Finally you'll turn your code into a command-line script with modules, docstrings, error handling and logging, and keep its history in Git. Every module has a hands-on lab with exact results to check, and the capstone is a script that turns a messy season of grain deliveries into a clean file and a report, using nothing but Python's built-in tools. It's the foundation for Data Wrangling with pandas and NumPy.

What you'll learn

  • Explore data interactively in IPython, using its help, history, Tab completion and magic commands
  • Choose between lists, tuples, dictionaries and sets to store, count, group and de-duplicate records
  • Write decisions, loops, comprehensions and functions, including lambdas as sort keys, to clean and summarise data
  • Build Jupyter notebooks that mix code, Markdown, charts and magic commands, run cleanly from top to bottom and export to share
  • Turn notebook code into a documented command-line script that handles bad data and errors, tracked in Git

Skills you'll gain

Python, IPython, Jupyter notebooks, Lists, tuples, dictionaries and sets, Control flow, Functions and lambdas, Data cleaning with built-ins, Error handling, Command-line scripts, Git basics

Tools

Python 3, IPython, JupyterLab, matplotlib, Git

Before you start

None: it starts from zero and needs only school maths. You need a computer with Python 3 (python.org has installers); the labs install IPython, JupyterLab and matplotlib into a virtual environment, and module 5 uses Git. Python Programming with PyCharm teaches the language in an IDE, with debugging and testing; this course teaches it the way data scientists work, in IPython and Jupyter, so the two go well together.

Modules

  1. Introduction to Python and IPython

    Set up Python and IPython in a virtual environment, learn how Python code is laid out, and meet its basic types, with IPython's help, history and magic commands to explore as you go.

    • Python for data work, and the IPython shell (10 min)
    • Syntax, indentation and variables (10 min)
    • Numbers, text and truth: the basic types (12 min)
    • Hands-on lab: Explore a day of weather readings in IPython
  2. Built-in Data Structures

    Store and organise records with Python's four built-in collections, lists, tuples, dictionaries and sets, and learn which one fits each job, from counting and grouping to removing duplicates.

    • Lists: ordered, changeable sequences (12 min)
    • Tuples and unpacking: fixed records (10 min)
    • Dictionaries: look-ups, counts and groups (12 min)
    • Sets: unique values and fast membership (10 min)
    • Hands-on lab: Count, group and compare grain deliveries
  3. Control Flow and Functions

    Make decisions with if, elif and else, repeat work with loops and comprehensions, and package your logic in functions and lambdas that parse, clean and summarise messy readings.

    • Decisions: if, elif and else (10 min)
    • Loops and comprehensions (12 min)
    • Functions: def, parameters and return values (12 min)
    • Lambdas and functions as values (10 min)
    • Hands-on lab: Clean a station's readings with functions
  4. Working with Jupyter Notebooks

    Explore and explain your work in JupyterLab: notebooks that combine code, results, Markdown text and charts, magic commands for timing, files and modules, and exports that others can read.

    • JupyterLab, notebooks and kernels (12 min)
    • Markdown cells: explain your analysis (10 min)
    • Magic commands (12 min)
    • Charts, sharing and reproducible notebooks (10 min)
    • Hands-on lab: Build and share a notebook about July's weather
  5. Python Scripting Lab

    Turn exploratory code into a script you can rerun and share: functions in modules, a command-line interface, error handling and logging for bad data, docstrings and comments, and a history in Git.

    • From notebook to script: modules and a main function (10 min)
    • Errors and exceptions: scripts that survive bad data (12 min)
    • Docstrings, comments and version control with Git (12 min)
    • Hands-on lab: Build a command-line station report

Project: Data Analysis Scripting Lab: clean a season of grain deliveries

A farm co-operative's grain elevator has exported a season of deliveries (made-up data) to deliveries_raw.csv, and it's messy: some rows were exported twice; farm and crop names are typed in several ways, including the aliases Prairie Rose, N. Star Grain and Birch Ck Farm; weights are in tonnes (21.4 or 21.4 t) or kilograms (21400 kg or 21,400 kg); moisture is sometimes blank, n/a or written with a % sign; dates are written 2025-08-14 or 14/08/2025; and a few rows are impossible. Write a Python script, using only the standard library and built-in data structures (no pandas), that reads the file, cleans it and writes clean_deliveries.csv, rejected.csv (each rejected row with its reason) and report.md, a summary for the co-operative's board. The rules: remove exact duplicate rows; give every farm one spelling (strip, title case, then the aliases) and every crop one (strip, lower case); convert weights to tonnes; keep missing moisture empty rather than inventing a value; write dates as YYYY-MM-DD; and reject rows with no weight, a weight of 0 or less or over 45 t, or moisture over 40%. The report gives the tonnes and loads by crop and by month, the top five farms, the mean moisture by crop (and how many values were missing), the loads by crop over the co-operative's drying threshold of 14.5% moisture, and a data-quality section. Check yourself: these rules give 166 rows read, 6 duplicates removed, 6 rows rejected and 154 loads kept, from 8 farms, totalling 3,343.7 t.

Part of

The products this course names are trademarks of their owners, who haven't made or endorsed it.

Start the course free