Google Colab
Google Drive
Data Reading
Python
Cloud Storage

How to read data in Google Colab from my Google drive?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

In Google Colab, the normal way to read files from your Google Drive is to mount Drive into the notebook file system and then open files by path. Once mounted, Drive behaves much like a regular directory, so pandas, pathlib, and Python file I/O work as expected. The main points to get right are authentication, the exact file path, and choosing the right reader for the file format.

Mount Google Drive in Colab

Start by mounting your drive. Colab will prompt you to authorize access.

python
from google.colab import drive

drive.mount('/content/drive')

After mounting, your personal drive is usually available under /content/drive/MyDrive. Verify the path before trying to read data.

python
1from pathlib import Path
2
3root = Path('/content/drive/MyDrive')
4print(root.exists())
5print(list(root.iterdir())[:5])

Checking the path early saves time because many Colab “file not found” errors come from a spelling mismatch rather than a real access problem.

Read Common File Types

Once the drive is mounted, reading a dataset is the same as reading a local file.

Read a CSV file with pandas:

python
1import pandas as pd
2from pathlib import Path
3
4csv_path = Path('/content/drive/MyDrive/datasets/sales.csv')
5df = pd.read_csv(csv_path)
6print(df.head())

Read an Excel workbook:

python
excel_path = Path('/content/drive/MyDrive/datasets/report.xlsx')
df = pd.read_excel(excel_path, sheet_name='Sheet1')
print(df.head())

Read a text file with standard Python I/O:

python
text_path = Path('/content/drive/MyDrive/datasets/notes.txt')
with text_path.open('r', encoding='utf-8') as handle:
    print(handle.readline())

The only real difference from local Python is that the data lives in mounted cloud storage.

Use Path Objects for Safer Paths

Hard-coded string paths work, but pathlib.Path tends to make notebooks clearer and easier to maintain.

python
1from pathlib import Path
2
3base = Path('/content/drive/MyDrive/datasets')
4file_path = base / 'customers.csv'
5
6if file_path.exists():
7    df = pd.read_csv(file_path)
8    print(df.shape)

This style reduces small path mistakes and makes it easier to move a notebook between folders.

Reading Large Files Efficiently

Drive-backed files can be slower than ephemeral local storage, especially for large datasets. When the file is big, read only what you need.

python
1import pandas as pd
2
3chunks = pd.read_csv('/content/drive/MyDrive/datasets/large.csv', chunksize=10000)
4first_chunk = next(chunks)
5print(first_chunk.head())

For repeated heavy processing, it can help to copy the file into /content first so later reads hit the Colab runtime disk rather than the mounted drive.

Working with Shared Files and Folders

If the file was shared with you, it may not be in the same folder you expect. The easiest way to avoid confusion is to add the file or folder to your own Drive and then confirm the mounted path from the Colab file browser or with Path.iterdir().

For team notebooks, it also helps to keep all datasets under one project folder so the notebook path logic stays stable across collaborators.

Common Pitfalls

  • Forgetting to run drive.mount after the runtime restarts.
  • Using the wrong path, especially around folder names and capitalization.
  • Assuming every file should be read with read_csv when the actual format is Excel, JSON, or plain text.
  • Expecting mounted Drive storage to be as fast as local runtime storage for very large files.
  • Sharing a notebook without considering that other users may not have permission to the same Drive path.

Summary

  • Mount Google Drive with drive.mount('/content/drive').
  • Most personal files appear under /content/drive/MyDrive.
  • Read Drive files with the same Python libraries you would use locally.
  • Use pathlib.Path to manage paths more safely.
  • For large datasets, read in chunks or copy data into local runtime storage when needed.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.