Book

So You Want to Be a Data Scientist

Python Primer for Data Science

A complete path from your first import to code other people depend on. Twenty-five short chapters covering the Python language itself, NumPy and pandas, loading and cleaning real data, visualisation, the statistics you need to make an honest claim, and the scikit-learn interface. Written for someone who has never done data science, and assumes no mathematics beyond secondary school.

Getting Started

  1. 1A Language Worth LearningWhere Python came from, how a Christmas project named after a comedy troupe ended up running the world's science, and how the author got here by the slow route so that you do not have to.18 min read
  2. 2Should You Still Learn to Code?You are learning to program at the exact moment machines got good at programming. The honest answer concedes the premise completely, then asks what was ever the hard part.15 min read
  3. 3Why Python WonPython is a slow language that dominates a field obsessed with speed. Understanding that contradiction explains almost everything about how the tools are shaped and how you are meant to use them.18 min read · notebook

The Language

  1. 4Values, Types and NamesNumbers, text, true and false, and nothing. What a variable really is in Python, why some values can be changed and others cannot, and the one behaviour that surprises every beginner exactly once.25 min read
  2. 5Collections: Lists, Dicts, Sets and TuplesFour ways to hold several things at once. What each is good at, what each is terrible at, and how to pick between them by what the operation costs rather than by whichever one you learned first.30 min read
  3. 6Control Flow, Comprehensions and UnpackingLoops and conditions, then the comprehension syntax that replaces most of them. Plus the unpacking tricks that appear everywhere in data code and confuse everyone the first time they see them.28 min read
  4. 7Functions That BehaveArguments, defaults, scope and return values. Includes the mutable default trap, which catches every Python programmer exactly once, and the docstring habit that makes code survivable six months later.28 min read
  5. 8Iterators, Generators and Context ManagersHow Python processes things one at a time without loading everything at once, and the with statement that guarantees cleanup. This is the chapter that lets you read a file bigger than your memory.30 min read
  6. 9Errors, Modules and the Standard LibraryHow to fail usefully, how to split code across files without circular imports, and the seven standard library modules that come up constantly in data work.30 min read

The Numerical Stack

  1. 10NumPy: Thinking in ArraysWhat an array actually is in memory, why shape matters more than value, the difference between a view and a copy, and the broadcasting rules that make mismatched arrays work exactly as you intended.40 min read · notebook
  2. 11Pandas: The Eighty Per CentIn the real world you are never handed a clean dataset. What arrives has eleven spellings of one category, dates in three formats, and a merge that silently triples your row count. This is the chapter about that.45 min read · notebook

Working With Real Data

  1. 12Getting Data In: Files and FormatsLoading a file is the first thing you do and the first thing that goes wrong. Encodings, delimiters, the read_csv arguments that are not optional, and why Parquet should be your default for anything you open twice.30 min read · notebook
  2. 13Getting Data In: Databases and APIsWhen the data is not in a file. Connecting to a database without pulling the whole table, writing queries that cannot be injected into, and calling an API politely enough that it keeps answering.30 min read
  3. 14Cleaning and ReshapingThe unglamorous majority of the job. Finding what is wrong, deciding what missing means, dealing with duplicates and outliers, and turning wide data into long and back again.35 min read · notebook
  4. 15Joining Without Losing RowsJoins are where the most expensive mistakes happen, because they fail by producing a plausible result with the wrong number of rows and no error at all. Three lines prevent nearly all of it.30 min read · notebook
  5. 16Working With TextThe .str accessor, normalising the five spellings of one category, and enough regular expressions to be useful without needing a decoder ring next month.30 min read · notebook
  6. 17Dates, Times and Time ZonesParsing dates that arrive in three formats, storing them so they survive a daylight saving change, and the resampling that turns raw timestamps into something you can plot.30 min read · notebook
  7. 18Categories and EncodingThe categorical dtype that saves memory and prevents mistakes, and the four ways to turn a category into a number. One of those four leaks the target into your training data, which is why it needs its own section.28 min read · notebook

Seeing the Data

  1. 19Visualisation That Isn't DecorationCharts that answer a question rather than fill a slide. Matplotlib's object model, the six chart types that carry nearly all the load, and the difference between a plot for you and a plot for other people.32 min read · notebook

Making Claims

  1. 20The Statistics You Actually NeedNot a statistics course. The specific ideas that stop you believing a result that is not there, taught with simulation rather than proof, because seeing it happen a thousand times is more convincing than a formula.38 min read · notebook
  2. 21Evaluation, and How It Lies to YouThe most expensive mistake in this field is not building a bad model. It is building a bad model your own evaluation says is excellent, and finding out from a customer. This is the chapter to read twice.40 min read · notebook

Modelling

  1. 22scikit-learn: The Interface, Not the AlgorithmsOne API covers every model in the library, and learning that API is a Python skill rather than a machine learning one. This chapter teaches the contract, the Pipeline that makes leakage structurally impossible, and nothing at all about how a random forest works.45 min read · notebook
  2. 23Feature Engineering That SurvivesMost model improvement comes from better features, not better algorithms. The techniques that generalise, and the specific ways a feature that works in a notebook turns out to be impossible to compute in production.35 min read · notebook

Shipping

  1. 24From Notebook to Something That RunsA notebook is a research artifact. Getting to code that runs on a schedule, can be tested, and can be rolled back is a different discipline, and it is where most data science projects stall.35 min read
  2. 25Performance When It Actually MattersMost slow code is slow for one of about five reasons. How to find which one, the fixes in order of effort, and an honest account of when to stop optimising pandas and use something else.32 min read