📱
Real-world scenario
Aisha in Nairobi: wrangling M-Pesa data at a café

Aisha works as a fintech analyst in Nairobi. Every week, she downloads M-Pesa transaction files and needs to spot trends—total volume, top customers, fraud patterns. She's done this in Excel for two years, but the datasets are growing. One notebook can replace a thousand Excel formulas and run in seconds.

This lesson teaches her the fastest way to get there: Jupyter on her laptop, or Google Colab (zero setup, instant access).

This is what data analysis looks like

A notebook is a live script. You write code, it runs instantly, and you see the output below. No compilation, no waiting—just explore.

Untitled.ipynb · Python 3 Last saved 2:34 PM
[1]:
import pandas as pd # Load M-Pesa transactions df = pd.read_csv('mpesa_feb.csv') df.head()
txn_id date amount customer_id till_number 001 2026-02-01 15000 C_KE_0042 SAFM_NAIROBI_01 002 2026-02-01 8500 C_KE_0156 SAFM_WESTLANDS 003 2026-02-01 42000 C_KE_0089 SAFM_KAREN 004 2026-02-01 5200 C_KE_0042 SAFM_NAIROBI_01 005 2026-02-02 127000 C_KE_0295 SAFM_KAREN
What this shows: One click, one line of code (df.head())—and you see the first 5 rows of your data. Amounts in KSh, transaction IDs, dates, customer IDs, till numbers. This is the starting point for every analysis.

Jupyter vs Colab vs VS Code notebooks

Three ways to write Python analysis. Each has a place. Here's how to pick:

Tool Setup Best for Downsides
Jupyter Notebook 5 mins (pip install) Local data, full control, offline work Need Python installed, manual dependency management
Google Colab 30 seconds (open browser) Quick experiments, team sharing, free GPU Slower CPU, auto-closes after inactivity, files in Drive
VS Code notebooks 10 mins (install extension) Heavy development, debugging, version control More overhead, less community support for notebooks
Rule of thumb: Starting out? Pick Colab (zero friction). Working on production pipelines? Pick Jupyter + git. Building an ML model? Pick Colab for speed, Jupyter for reproducibility.

Install Jupyter on your laptop (5 minutes)

Open your terminal (Mac: Terminal.app, Windows: Command Prompt or PowerShell, Linux: any shell) and paste these commands.

Step 1: Install pandas, matplotlib, and Jupyter

terminal bash

Step 2: Start Jupyter

This command opens Jupyter in your browser at http://localhost:8888. The first time, Jupyter prints a token—paste it into the browser if it doesn't auto-login.

terminal bash
Expected output
[I 14:32:15.892 NotebookApp] Jupyter Notebook 6.5.4 [I 14:32:15.893 NotebookApp] ... running at http://localhost:8888/ [I 14:32:15.893 NotebookApp] ... Use Control-C to stop this server

Step 3: Verify pandas is installed

Click "New → Python 3" to create a notebook, then paste this code into a cell and press Shift+Enter:

notebook cell python
1.5.3
Success: Your Jupyter is ready. You'll see the pandas version printed. If you see an error like "No module named pandas", run pip install pandas again.

Or use Google Colab (zero setup)

No laptop setup needed. If you have a Google account, you have Colab. Go to colab.research.google.com, click "New notebook", and you're live in 10 seconds.

4 reasons Colab wins for analysts:
  1. Free GPU. Heavy data? Colab offers free GPU acceleration for intensive operations.
  2. Auto-save to Google Drive. No worrying about lost work—Colab syncs to Drive automatically.
  3. Shareable like Google Docs. Invite teammates to collaborate in real-time on the same notebook.
  4. Pre-installed pandas. Import pandas, numpy, matplotlib, sklearn—all ready to go. No pip install needed.

Setup time comparison:

Time to first code cell
Bar chart comparing setup time: Jupyter 5 min, Colab 0.5 min, VS Code 3 min
Takeaway: Colab is 10x faster to start. If you're learning, start with Colab. If you need more control, move to Jupyter.

Your first notebook: load and explore M-Pesa data

Let's walk through a real analyst workflow. We'll load a tiny M-Pesa dataset (100 transactions), explore it, and extract insights—all in 4 cells.

Cell 1: Import pandas

Every notebook starts here. This loads the pandas library.

cell [1] python
Output
Pandas ready!

Cell 2: Load the CSV

The CSV file lives on your disk (or in Colab's Drive). pd.read_csv() converts it into a DataFrame—a table you can manipulate.

cell [2] python
Output
Loaded 100 transactions

Cell 3: View the data

The magic cell. df.head() shows the first 5 rows. This is how you sanity-check: "Do the dates look right? Are the amounts in KSh? Are there nulls?"

cell [3] python
txn_id date amount customer_id till_number
M001 2026-02-01 15000 C_KE_0042 SAFM_NAIROBI_01
M002 2026-02-01 8500 C_KE_0156 SAFM_WESTLANDS
M003 2026-02-01 42000 C_KE_0089 SAFM_KAREN
M004 2026-02-01 5200 C_KE_0042 SAFM_NAIROBI_01
M005 2026-02-02 127000 C_KE_0295 SAFM_KAREN
What you see: 5 rows, all the columns. Amounts are in KSh, dates look right, customer IDs are present. This passes the sniff test.

Cell 4: Answer a question

Now compute. What's the total transaction volume for February?

cell [4] python
Output
Total February volume: KSh 12,847,320
That's the workflow. Load → Explore → Compute → Decide. Every analyst notebook follows this rhythm, whether analyzing M-Pesa, Safaricom Daraja, or Jumia sales.

Keyboard shortcuts that save hours

Notebooks reward speed. Learn these and you'll fly through analysis:

Shortcut Action Why it matters
Shift + Enter Run cell Your most-used shortcut. Run code and move to next cell.
Ctrl + Enter Run cell (stay) Run code but stay in the same cell. Good for tweaking parameters.
Esc + A Insert cell above Add a new cell above the current one.
Esc + B Insert cell below Add a new cell below the current one. Most common.
Esc + DD Delete cell Remove a cell (press Esc, then D twice fast).
Esc + M Convert to Markdown Turn a code cell into a text cell (for notes).
Esc + Y Convert to Code Turn a Markdown cell back into code.
Tab Autocomplete Type df.gr, press Tab, Jupyter suggests groupby. Saves typing.
Pro tip: Press H in a notebook to see all keyboard shortcuts. (Or Esc + H in Jupyter.)

Where you see this

Industries & use cases

💰
Fintech & Payments
M-Pesa, Safaricom Daraja, Razorpay: analysts use notebooks to detect fraud, calculate daily settlements, optimize merchant fees.
📊
E-commerce Analytics
Jumia, Kilimall, Flipkart: run queries on user behavior, inventory, and sales dashboards—all in a notebook.
📱
Telecom & Mobile
Safaricom, Airtel: churn prediction, usage patterns, revenue analytics—all start in a notebook.

How this connects to AI

Notebooks are where data scientists build ML models. You load data with pandas (this lesson), explore it (next lesson), clean it (arc 3), then feed it into TensorFlow or scikit-learn to build fraud detectors, churn predictors, and recommendation engines. Colab is popular for ML because it offers free GPU—perfect for training models on large datasets.

interactive development rapid prototyping model training

Mini Challenge

Task: Open Google Colab (colab.research.google.com), create a new notebook, and create 3 cells:

  1. Import pandas
  2. Load a sample CSV (you can create one or use a public dataset)
  3. Run df.head() to display the first 5 rows

Once you see a table printed, you've completed the challenge. Bonus: try df.describe() in a 4th cell to see descriptive statistics.

Hint: Use !pip install pandas if needed (Colab usually has it pre-installed). For a test dataset, try df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv').

Interview questions

A Jupyter notebook is an interactive document that mixes code, output, and markdown notes. You write Python in cells, press Shift+Enter to run, and see results instantly. It's perfect for exploratory analysis—you can tweak code and re-run without rewriting everything.
Start with Colab if you're learning—zero setup, free GPU, and sharing is easy. Use Jupyter if you want full control, work offline, or integrate with version control (git). Many analysts use both: Colab for exploration, Jupyter for production pipelines.
Both load data, but pandas handles much larger files (millions of rows) and is repeatable. You write code once; it runs the same every time. Excel is visual and good for ad-hoc work, but if you load data 100 times a month, code is faster and less error-prone.
Shift+Enter runs the current cell and moves to the next one. It's the heartbeat of notebook work. You type code, Shift+Enter, see the output, then move on. If you want to stay in the same cell, use Ctrl+Enter instead.
Use pip install package_name in a code cell (prefix with ! in Jupyter). Or create a requirements.txt file and run pip install -r requirements.txt in your terminal. For reproducibility, always pin versions: pip install pandas==1.5.3 ensures everyone runs the same code.

Test your knowledge

Question 1 of 4
What does Shift+Enter do in a Jupyter notebook?
Question 2 of 4
Which tool requires zero setup?
Question 3 of 4
What does df.head() do?
Question 4 of 4
How do you load a CSV file into Pandas?
0
/4
Great work! You're ready for the next lesson.

Cheatsheet

Task Code Result
Load CSV into DataFrame df = pd.read_csv('data.csv') DataFrame from file
View first 5 rows df.head() First 5 rows displayed
View last 3 rows df.tail(3) Last 3 rows
DataFrame shape df.shape (rows, columns)
Column names df.columns List of column names
Data types df.info() Columns, types, nulls
Summary statistics df.describe() Mean, std, min, max per column
Sum a column df['amount'].sum() Total of that column
Count rows len(df) Number of rows
Save to CSV df.to_csv('out.csv', index=False) Exports DataFrame to file

Common pitfalls

Kernel not starting
If Jupyter gives an error on startup, try restarting the kernel: Kernel → Restart in the menu. If that fails, close the terminal and run jupyter notebook again in a fresh terminal.
File not found error
Make sure your CSV is in the same folder as your notebook, or use the full path: pd.read_csv('/Users/aisha/data/mpesa.csv'). In Colab, upload files to Drive and use from google.colab import drive; drive.mount('/content/drive').
ModuleNotFoundError: No module named 'pandas'
Run pip install pandas in your terminal (outside the notebook). If you're in Colab, run !pip install pandas in a cell. If Jupyter is using a different Python version, check with which python and which pip.
Forgetting to save
Jupyter auto-saves every few minutes, but save manually with Ctrl+S (or Cmd+S on Mac) to be safe. Colab auto-saves to Drive—you can't lose work.
Running cells out of order
Notebooks run top-to-bottom. If you skip a cell that defines a variable, later cells will fail. Always run cells in order, or click Kernel → Restart & Run All to reset everything.

Key takeaways

Jupyter notebooks: Interactive, cell-based Python environment. Perfect for data exploration and analysis. Install locally, run offline, full control.

Google Colab: Browser-based notebook with zero setup, free GPU, and auto-save to Drive. Best for learning and quick experiments.

Keyboard shortcuts: Shift+Enter (run cell), Esc+B (new cell below), Esc+DD (delete cell). Mastering these saves hours.

Workflow: Load CSV → explore with df.head() → check with df.describe() → ask questions and compute answers.

Next steps: Every analyst you know uses notebooks. Once you're comfortable here, you'll move to cleaning data (nulls, duplicates), then exploring (groupby, pivot), then visualizing (charts).

Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

Ready to move beyond spreadsheets?

Join the Best AI Program: The AI-Era Analyst — 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Analyst →