How to read data in Google Colab from my Google drive?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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.
After mounting, your personal drive is usually available under /content/drive/MyDrive. Verify the path before trying to read data.
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:
Read an Excel workbook:
Read a text file with standard Python I/O:
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.
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.
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.mountafter the runtime restarts. - Using the wrong path, especially around folder names and capitalization.
- Assuming every file should be read with
read_csvwhen 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.Pathto manage paths more safely. - For large datasets, read in chunks or copy data into local runtime storage when needed.

