Google Colab · CSV · File upload
How to upload local files and read CSV in Google Colab (without FileNotFoundError)
One of the most common beginner errors in Colab is:
FileNotFoundError: [Errno 2] No such file or directory.
It usually happens because Colab is running on a remote machine, not on your C: drive.
3 ways to get files into Google Colab
- Upload a file directly from your computer.
- Mount Google Drive and read files from there.
- Download from a URL (GitHub / Kaggle / etc.) into Colab.
Method 1 – Upload a local CSV file from your computer
Use the built-in file upload widget:
from google.colab import files
import io
import pandas as pd
uploaded = files.upload() # Choose file in the dialog
# Assume you uploaded "data.csv"
df = pd.read_csv(io.BytesIO(uploaded["data.csv"]))
df.head()
For quick experiments and small datasets, this is easiest. But you’ll have to re-upload every time the runtime resets.
Method 2 – Upload using the file browser pane
On the left side of Colab click the folder icon → click the upload icon and choose your CSV.
Colab will place it under /content/.
import pandas as pd
df = pd.read_csv("/content/data.csv")
df.head()
"C:\\Users\\you\\Desktop\\data.csv".
Colab cannot see your local C: drive – you must upload the file or put it in Google Drive.
Method 3 – Mount Google Drive and read CSV
For bigger projects and final-year work, you should store data in Drive so it persists and is easy to share.
from google.colab import drive
drive.mount("/content/drive")
After mounting, your Drive is available under:
/content/drive/MyDrive/
So if your file is in MyDrive/projects/ml/data/train.csv:
import pandas as pd
csv_path = "/content/drive/MyDrive/projects/ml/data/train.csv"
df = pd.read_csv(csv_path)
df.head()
Fixing common FileNotFoundError issues
1. Wrong path (typo or wrong folder)
Always print the current working directory and list files:
import os, glob
print(os.getcwd())
print(glob.glob("*"))
print(glob.glob("**/*.csv", recursive=True))
This helps you find the real path that Colab sees.
2. File in the wrong Drive account
If you mounted a different Google account than expected, the file might simply not exist under that Drive. Confirm by browsing the left-side Drive pane.
3. Using relative paths incorrectly
If your notebook is inside /content/drive/MyDrive/project/ and data is in
data/train.csv, you can do:
import pandas as pd
df = pd.read_csv("data/train.csv")
But this only works if your working directory is the project root. Safest is to use absolute paths.
Make your Colab data paths reproducible with NoteCapsule
Once your notebook and CSV paths finally work, capture that working state so you never have to debug paths again right before a deadline.
!pip install "git+https://github.com/YOUR_GITHUB_USERNAME/notecapsule.git@main"
from notecapsule import create_capsule
create_capsule(
name="colab-csv-project",
notebook_path="your_notebook.ipynb",
data_dirs=["./", "/content/drive/MyDrive/projects/ml/data"],
base_dir="."
)
NoteCapsule records the notebook, a manifest of your CSV files, and the environment so you can re-run
or share it confidently.