THE GENIUS PROJECT
☁️ Lesson 8 of 9

Google Colab

πŸ•’ About 20 minutes πŸ’» Nothing to install πŸ†“ Completely free

Everything you have written so far can run for real, and you do not need to install a thing. Google Colab gives you Python inside your browser, running on Google's computers, for free. This lesson takes you from "never opened it" to "ran my first notebook" in a handful of steps.

What Colab actually is

Colab (short for Colaboratory) is a free website where you write and run Python. Instead of installing software on your laptop, your code runs on Google's machines and the results appear in your browser. All you need is a free Google account and an internet connection. The tools you met in Lesson 4, including scikit-learn, pandas, and matplotlib, are already installed for you.

A notebook is a stack of cells

Colab files are called notebooks. A notebook is a vertical stack of boxes called cells. There are two kinds: code cells that run Python, and text cells that hold notes and headings (like the paragraph you are reading). A single code cell looks like this, with its parts labelled.

print("Colab is working")
Colab is working

The round ▶ run button on the left runs the cell. The code is in the middle. The output appears just below, right after you run it.

Getting started, from zero

You need one thing: a free Google account, the same one you use for Gmail or YouTube. The first time, go through these in order. It takes about two minutes.

  1. Open Colab and sign in. Go to colab.research.google.com. If you are not already signed in to Google, it will ask, use any Google account.
  2. Start a new notebook. On the welcome pop-up, click New notebook (or File → New notebook). A blank notebook opens with one empty code cell.
  3. Name it. Click the title Untitled0.ipynb at the top left and rename it, say world-cup-lab, so you can find it again later.
  4. Type in the cell. Click inside the empty box and type print("Colab is working").
  5. Run it. Press Shift + Enter, or click the round ▶ button on the left. The first run takes a few seconds, because Colab is connecting you to a free computer in the cloud (a "runtime"). After that, cells run instantly.
  6. Read the brackets. The [ ] on the left of a cell fills with a number, like [1], once it has finished. That number is the order cells actually ran in, not their order on the page. A spinning circle means it is still working.
  7. Add more cells. Hover between cells and use + Code for another code box, or + Text for a note. A notebook grows downward as a stack.
  8. Save. File → Save a copy in Drive. It is stored in your Google Drive and shares exactly like a Google Doc. pandas, numpy, matplotlib, and scikit-learn are already installed, so you never have to set anything up.
✍️ Fill in the Colab basics
To run a cell and jump to the next one, press . Before you can use pandas, you first have to it. And if your notebook starts acting up, use Runtime then .

Paste this into your first cell

This is a complete, working first notebook. It prints a message, makes a small table of the four teams whose flags open this course, and draws a bar chart of their FIFA rankings. Copy it into a Colab code cell and press Shift + Enter.

▢️ your first Colab cell
import pandas as pd
import matplotlib.pyplot as plt

print("Colab is working.")

teams = pd.DataFrame({
    "team": ["CuraΓ§ao", "Haiti", "Morocco", "Argentina"],
    "fifa_rank": [41, 37, 19, 1]
})
print(teams)

plt.bar(teams["team"], teams["fifa_rank"])
plt.title("FIFA ranking (lower is better)")
plt.show()

If it runs without a red error box and draws a little bar chart, your notebook works, and every code block from Lesson 4 will run the exact same way.

The one thing that trips everyone up

Cells do not have to be run top to bottom. You can run any cell at any time, and Colab remembers whatever you have run in the order you ran it. That is powerful, but it causes the classic beginner bug: you change an early cell, forget to re-run it, and a later cell keeps using the old value.

⚠️ The fix everyone learns

If your notebook starts acting strangely and you are not sure why, use Runtime → Restart and run all. It wipes Colab's memory and runs every cell fresh from the top, in order. Nine times out of ten, that clears up a confusing bug.

Uploading your own data

Real projects use real data, usually a CSV file: a spreadsheet saved as plain text, which is the format FBref and Kaggle hand you. There are three common ways to get one into Colab. Start with the first.

Method 1: drag it in (quick, but temporary)

  1. Click the folder icon on the far left edge of Colab to open the Files panel.
  2. Drag your CSV straight into that panel, or use the upload button at the top of it. Your file shows up in the list.
  3. Read it into a table with two lines:
🐍 read an uploaded CSV
import pandas as pd

df = pd.read_csv("matches.csv")   # use the exact file name you uploaded
df.head()                          # show the first 5 rows
⚠️ Uploaded files do not stick around

Files you drag in disappear when the runtime resets, which happens after a while idle or if you restart. That is fine for a quick test, but for anything you will reopen tomorrow, use Method 2.

Method 2: connect your Google Drive (keeps your files)

Mount your Drive once and Colab can read any file in it, and those files stay put between sessions.

🐍 mount Google Drive
from google.colab import drive
drive.mount("/content/drive")

# then read a file you saved in Drive:
import pandas as pd
df = pd.read_csv("/content/drive/MyDrive/matches.csv")
df.head()

The first time, Colab pops up a window asking you to allow access to your Drive. Click through it with your Google account and you are set.

Method 3: read straight from a web link

If the data is already online as a CSV, and many World Cup datasets are, skip the download entirely and hand pandas the link.

🐍 read a CSV from a URL
import pandas as pd

url = "https://example.com/world_cup_matches.csv"
df = pd.read_csv(url)
df.head()

Whichever method you use, once the data is sitting in df you can chart it (the matplotlib code from Lesson 4) or feed it to a model with .fit(X, y). Same df, same code you already know.

βœ‹ Quick check
You drag a CSV into the Files panel, use it, then come back tomorrow and it is gone. Why?
βœ‹ Check your understanding
You change a value in an early cell but a later cell still shows the old result. What is the safest fix?
πŸš€ A real dataset to try

Search Kaggle for "FIFA World Cup" or open the free StatsBomb data, download a CSV of past matches, upload it to Colab, and train the two models on real results. The World Cup is producing fresh data every day right now, the best kind of practice there is.

🧠 Recap
  • Colab runs Python free in your browser; nothing to install.
  • A notebook is a stack of cells: code cells run Python, text cells hold notes.
  • Shift + Enter runs a cell; scikit-learn, pandas, and matplotlib are pre-installed.
  • Cells run in the order you run them, so Restart and run all fixes most confusing bugs.
  • Upload a CSV, then pd.read_csv(...) to use your own data.

Last stop: prove what you know, then predict the real World Cup.