Skip to content

Google Colab guide

Google Colab is a Python notebook environment that runs in your browser. You don't need to install anything, just a Google account. The whole course, including the project, is done here.

1. Open a course notebook

  1. On the classes page, click Open in Colab.
  2. The notebook opens in read-only mode. To edit it, go to File › Save a copy in Drive.
  3. Your copy is saved in the Colab Notebooks folder of your Google Drive.

2. Run code

Action How
Run the current cell and move to the next one Shift+Enter
Run the whole notebook Runtime › Run all
Start from scratch Runtime › Restart session and run all
Add a code or text cell + Code and + Text buttons

Order matters

Colab remembers the variables from cells you already ran, even if you delete those cells. If something works "sometimes", restart the session and run everything from top to bottom.

3. Load data

The recommended way in this course is to read the file directly from its URL. It works the same for everyone and doesn't depend on your Drive:

import pandas as pd

url = "https://raw.githubusercontent.com/hizocar/usm-course-intensivo/main/docs/datasets/loan_default.csv"
df = pd.read_csv(url)
df.head()

The URL of each file is on the datasets page. Two other options:

from google.colab import files
uploaded = files.upload()   # opens a file picker
df = pd.read_csv("your_file.csv")

The file is deleted when the Colab session ends.

from google.colab import drive
drive.mount("/content/drive")
df = pd.read_csv("/content/drive/MyDrive/folder/file.csv")

Every team member would need the file at the same path, so for the project the URL is a better choice.

4. Libraries

Colab already includes pandas, NumPy, matplotlib, seaborn, scikit-learn, and statsmodels. If you need something else, install it in a cell:

!pip install xgboost

5. Teamwork and sharing the project

  1. One team member creates the project notebook and shares it with the rest of the team as Editor (the Share button, top right).
  2. Also share it with hizocar@gmail.com as Commenter. That way I can review your progress at each sprint without you having to send anything.
  3. Several people can open the same notebook in Colab, but if two people edit at the same time they can overwrite each other's changes. Split the work by section and let the team know before you run everything.

6. Before the final submission

  • Runtime › Restart session and run all finishes without errors.
  • The data is read from a URL, not from a path on your computer or your Drive.
  • Each section has a heading and text explaining what was done and what you conclude.
  • You downloaded the file with File › Download › Download .ipynb.
Back to top