Module 24 · Your Turn

What do five lines of code get you that a spreadsheet doesn’t?

Lesson 24.3 · Try Python in Your Browser

Ashley · Felix

Five lines. Nothing installed. Same answer, repeatable forever.

Ashley has 400 videos from a dozen channels now, not sixteen.

The spreadsheet is getting slow and she keeps redoing the same pivot. Felix shows her five lines in a browser notebook.

Nothing to install. The five lines do what the spreadsheet did, and they’ll do it again tomorrow with one click.

The short answer

The same pivot and chart Ashley made by hand, written down so it runs again on 400 videos, then 500, with one click. And describe() found two videos with a length of zero minutes in the first second. Module 5 never stops being useful.

Try it yourself

Walk through the starter notebook one line at a time, with what each line prints.

import pandas as pd
df = pd.read_csv("pokemon.csv")
(no output, the table is loaded)

Line 1 loads pandas, the library that turns Python into a spreadsheet you talk to. Line 2 reads the CSV into a table called df.

Step 1 of 4

What you just did has a name

A notebook

A notebook is a web page where you type a few lines of code, run them, and see the result right underneath.

Kaggle Notebooks, Google Colab and JupyterLite all run in the browser with nothing to install.

The five lines are the same in all three, and “file and column names change” is the only thing you edit.

A few more things

Code is a recipe you can rerun

The spreadsheet pivot is a thing you did. The five lines are a thing you wrote down. Tomorrow’s 400 videos become 500, and the recipe runs again in one click. That’s the whole reason to learn it.

It’s the same moves

read_csv is opening the file. describe is Module 5’s range check. groupby is a pivot. plot is a chart. Nothing new happened. It just got a name you can type.

Where to run it

JupyterLite needs no account at all. Colab needs a Google account (check the age rules). Kaggle Notebooks attach any Kaggle dataset in one click, with the same account note as lesson 24.1.

Go deeper

The longer version, if you want it.

What comes after five lines

The next five: filter rows (df[df.attack > 100]), add a column (df["total"] = df.hp + df.attack + df.defense + df.speed), sort (df.sort_values("total")), a scatterplot (df.plot.scatter("attack", "defense")), and a regression line, which a library called scikit-learn fits in three lines and which is the exact math from lesson 15.1.

From there the whole course is reachable in code: k-means is one function, a decision tree is one function, a train/test split is one function. The ideas were the hard part. You have those.

Quick check

Owen wants to try the five lines, but the family laptop is locked down and he can’t install anything. Can he?

Let’s take it slower

Think of a notebook as a chat window for code. You type a line, press run, and the answer appears right under it, like a reply. Then you type the next line under that. The page keeps every line and every reply, in order, so tomorrow you can open it and press run again from the top. The tools that host these pages do all the installing on their end. Your job is a browser tab, a dataset, and the same five lines with your file name swapped in.

More examples

1

The science fair partner

Two kids share a notebook link. One loads the data and writes the summary line, and the other opens the same page an hour later, sees the output already sitting there, and adds the chart line underneath. No emailing files back and forth: the page is the project.

2

Switching tools mid-project

Felix starts in a no-account notebook, then wants a bigger dataset that lives on Kaggle. He copies his five lines into a Kaggle notebook, changes the file name, and gets the same chart. The code doesn’t care which page it’s on.

Back to the question

So what do five lines get you?

Show the answer

The same pivot and chart Ashley made by hand, written down so it runs again on 400 videos, then 500, with one click. And describe() found two videos with a length of zero minutes in the first second. Module 5 never stops being useful.

One last question

What does the groupby line actually do?

Talk Card

Talk Card · 24.3

Five lines of Python in a browser notebook load a dataset, summarize it and chart it. Nothing to install, and it runs again with one click when the data changes.

Data to AI · pettigrewlab.com/learn

Next lesson