Google Colab Walkthrough
What is Google Colab?
Section titled “What is Google Colab?”Google Colab (Colaboratory) is a free, cloud-hosted Jupyter Notebook environment.
It allows you to:
- Run Python in the browser (no local install)
- Use free GPUs/TPUs (great for ML workloads)
- Share notebooks easily
- Connect to Google Drive
For data analytics, Colab is excellent when:
- Your machine is slow
- You want a quick setup
- You want to share a notebook link with others
Create a new notebook
Section titled “Create a new notebook”- Go to: https://colab.research.google.com/
- Sign in with a Google account
- Click New notebook
A notebook opens with a default code cell.
Understanding Colab interface
Section titled “Understanding Colab interface”Key menus you’ll use:
- Runtime: run cells, restart runtime, change hardware
- File: save a copy, download
.ipynb, download.py - Edit: find/replace, shortcuts
Colab runs notebooks on remote servers called a runtime.
Run your first code
Section titled “Run your first code”In a code cell:
print("Hello from Colab")Run with Shift + Enter.
Uploading datasets
Section titled “Uploading datasets”You have a few common options.
Option 1: Upload directly (temporary)
Section titled “Option 1: Upload directly (temporary)”- Left sidebar → Files
- Click Upload and choose your CSV
Important:
- Uploaded files are stored in the runtime temporary disk.
- If the runtime resets, uploaded files are gone.
Option 2: Google Drive (recommended)
Section titled “Option 2: Google Drive (recommended)”Mount your Drive:
from google.colab import drive
drive.mount('/content/drive')Then access files like:
import pandas as pd
path = "/content/drive/MyDrive/data/titanic.csv"
df = pd.read_csv(path)
df.head()Option 3: Download from a URL
Section titled “Option 3: Download from a URL”import pandas as pd
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/titanic.csv"
df = pd.read_csv(url)
df.head()Installing packages in Colab
Section titled “Installing packages in Colab”Colab has many libraries installed, but not everything.
Use pip inside a notebook:
!pip install yfinanceOr make it a bit quieter:
!pip -q install yfinanceChanging runtime hardware (GPU/TPU)
Section titled “Changing runtime hardware (GPU/TPU)”Runtime→Change runtime type- Set:
- Hardware accelerator: GPU (or TPU)
You can confirm GPU availability:
import torch
print("CUDA available:", torch.cuda.is_available())(If you don’t use PyTorch, you can also check with other tools.)
Saving and exporting your work
Section titled “Saving and exporting your work”Save to Drive
Section titled “Save to Drive”File→Save a copy in Drive
Download notebook
Section titled “Download notebook”File→Download→.ipynb
Export to Python
Section titled “Export to Python”File→Download→.py
Visualize it
Section titled “Visualize it”A Colab notebook is the same execute-explore experience as local Jupyter, just running on a remote machine.
flowchart LR A["Open colab.research.google.com"] --> B["New notebook"] B --> C["Connect to a runtime (CPU/GPU/TPU)"] C --> D["Mount Drive or upload data"] D --> E["Run cells with Shift+Enter"] E --> F["Save to Drive / download .ipynb"]
Colab tips for data analytics
Section titled “Colab tips for data analytics”Quickly preview data
Section titled “Quickly preview data”import pandas as pd
import numpy as np
df = pd.DataFrame({
"city": ["Delhi", "Mumbai", "Pune"],
"sales": [120, 90, 150]
})
dfDisplay full columns/rows (Pandas)
Section titled “Display full columns/rows (Pandas)”import pandas as pd
pd.set_option("display.max_columns", None)
pd.set_option("display.max_rows", 100)Continue to: Virtual Environments for Data Science to understand why environments matter and how to maintain clean project dependencies.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Build a Google Drive Path
Section titled “Exercise 1 – Build a Google Drive Path”Exercise 2 – Read CSV Data From a URL-like String
Section titled “Exercise 2 – Read CSV Data From a URL-like String”Exercise 3 – Check Whether a Runtime Has a GPU
Section titled “Exercise 3 – Check Whether a Runtime Has a GPU”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading