There are three main ways to load a file into Google Colab: upload it from your computer, mount Google Drive, or read it from a URL. Use an upload for a small, one-off CSV; use Drive for data you reuse or share with a team; and read public data straight from its URL.
This article gives the code for each, plus how to fix garbled Japanese CSVs (UnicodeDecodeError), how to read Excel files and Google Sheets, and how to download your results. The Colab code was checked against the official google.colab source code and Colab's official sample notebook, and the pandas parts were run locally (pandas 3.0).
- Methods at a glance
- Background: Colab files live in /content and disappear with the runtime
- Method 1: Upload files from your computer (files.upload)
- Method 2: Mount Google Drive and read from it (drive.mount)
- Japanese CSV is garbled or raises an error (cp932 / shift_jis)
- Read Excel files (.xlsx)
- Method 3: Read directly from a URL (GitHub raw, public CSV)
- Read Google Sheets (gspread)
- Download or save your results
- Common errors and fixes
- References
Methods at a glance
| Method | Best for | After a runtime restart |
|---|---|---|
files.upload() / drag into the Files panel | Analyzing a local CSV once | Gone |
drive.mount() | Data you reuse, saving results, sharing | Stays in Drive (mount again) |
| URL (GitHub raw, public CSV) | Public datasets, sample data | Still at the URL; just fetch it again |
gdown | A Drive file someone sent you as a share link | Download again |
gspread | Data in Google Sheets | Stays in the sheet |

Background: Colab files live in /content and disappear with the runtime
Colab runs your code on a virtual machine (VM) provided by Google. Files you upload or create from code are saved in the VM's working directory, /content. Click the folder icon on the left to open the Files panel and see what's there.
The catch is that the VM is deleted after it has been idle for a while, and it also has a maximum lifetime (Colab FAQ). Files you uploaded to /content are also lost when you run "Disconnect and delete runtime" or get disconnected by a timeout. Save any data or results you want to keep to Google Drive, or download them. Free-tier time limits are covered in Google Colab pricing and free tier limits.

To check the current working directory and list its files:
!pwd
!ls -la /content
Method 1: Upload files from your computer (files.upload)
To upload a local file from code, use upload() from google.colab.files. When you run it, a "Choose Files" button appears under the cell; pick the file on your computer.
from google.colab import files
uploaded = files.upload()
for name, data in uploaded.items():
print(f"{name}: {len(data)} bytes")
upload() returns a dictionary mapping file name to contents (bytes), and the files are saved to the working directory (normally /content). The source code shows two more behaviors:
- If a file with the same name already exists, the new one is saved with a number, like
data (1).csv. - If you pass
target_dir, that folder is created and the files are saved there (e.g.files.upload(target_dir="data")).
You can read the uploaded CSV with pandas right away:
import pandas as pd
df = pd.read_csv("/content/sales.csv")
df.head()
If you aren't sure of the file name, use the dictionary key:
import io
import pandas as pd
name = next(iter(uploaded)) # name of the first uploaded file
df = pd.read_csv(io.BytesIO(uploaded[name]))
Drag and drop into the Files panel
Without writing code, you can also drag and drop files into the Files panel (the folder icon on the left) to upload them to /content. Right-click the file name (or use its "More actions" menu) and choose "Copy path" to get the path to pass to pd.read_csv(). These files are also deleted along with the runtime.
Method 2: Mount Google Drive and read from it (drive.mount)
For data you use repeatedly, keep it in Google Drive and mount it.
from google.colab import drive
drive.mount('/content/drive')
When you run this, Colab asks for permission to access your Google account. Choose the account that owns the Drive and allow access. Once mounted, My Drive appears as /content/drive/MyDrive/.
import pandas as pd
df = pd.read_csv("/content/drive/MyDrive/ProjectA/data.csv")
df.head()
For a step-by-step setup including folder structure and where to keep notebooks, see how to set up an analysis environment with Google Drive and Colab.
drive.mount options and caveats
The signature of drive.mount() is mount(mountpoint, force_remount=False, timeout_ms=120000, readonly=False) (from the colabtools source).
force_remount=True: remounts even if Drive is already mounted. Use it when you see "Drive already mounted" and can't switch to another account.readonly=True: mounts read-only. Handy when you don't want to overwrite the source data by accident.drive.flush_and_unmount(): flushes pending writes to Drive, then unmounts.
The official FAQ also lists common Drive problems:
- If the top level of My Drive contains roughly 10,000 or more files and folders, mounting may time out. Move items into subfolders.
- Reading and writing many small files directly is slow and can hit Drive quota limits, resulting in
Input/output error. The recommended approach is to bundle them into a zip or tar.gz, copy it to the VM and extract it there. - Drive is not mounted automatically in notebooks that someone else has edited.
drive.mount()does not work on Colab Enterprise or local runtimes.
For large sets of images and similar data, copying to the VM first is much faster:
!cp /content/drive/MyDrive/datasets/images.zip /content/
!unzip -q /content/images.zip -d /content/images
Japanese CSV is garbled or raises an error (cp932 / shift_jis)
CSV files created by Excel or other Windows apps in Japan, and CSVs from Japanese government sources such as e-Stat, are often saved in a Shift_JIS-family encoding. pandas' read_csv() assumes UTF-8 by default, so you get this error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 0: invalid start byte
Fix it by setting encoding:
import pandas as pd
df = pd.read_csv("/content/drive/MyDrive/data_sjis.csv", encoding="cp932")
When in doubt, use "cp932" rather than "shift_jis". cp932 is Microsoft's extended version of Shift_JIS used on Windows, and it includes vendor-specific characters such as 髙 (a variant of 高 common in surnames) and ①. We created a CSV locally containing "髙橋①": encoding="shift_jis" raised a UnicodeDecodeError, while encoding="cp932" read it correctly.
| encoding | When to use it |
|---|---|
| Not set (utf-8) | CSVs exported from Google Sheets, Python, etc. |
"utf-8-sig" | UTF-8 with BOM (Excel's "CSV UTF-8" format) |
"cp932" | Excel "CSV (Comma delimited)" on Japanese Windows, Japanese government CSVs, etc. |
"shift_jis" | Shift_JIS without vendor-specific characters. cp932 covers this too |
Going the other way, if a CSV created in Colab looks garbled when opened in Excel, write it as UTF-8 with BOM:
df.to_csv("/content/result.csv", index=False, encoding="utf-8-sig")

Read Excel files (.xlsx)
Read Excel files with pd.read_excel(). It uses openpyxl for .xlsx files (usually preinstalled on Colab; on your own machine you may need pip install openpyxl).
import pandas as pd
path = "/content/drive/MyDrive/report.xlsx"
# Read a specific sheet by name
df = pd.read_excel(path, sheet_name="2025")
# Read every sheet into a {sheet name: DataFrame} dictionary
sheets = pd.read_excel(path, sheet_name=None)
print(list(sheets.keys()))
Excel files store their text encoding internally, so you don't need an encoding argument as you do with CSV. If there are title rows above the table, use skiprows=; if the header is on the second row, use header=1.
Method 3: Read directly from a URL (GitHub raw, public CSV)
A CSV that is publicly available online can be read by passing its URL to read_csv().
import pandas as pd
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
df = pd.read_csv(url)
print(df.shape) # (150, 5)
For files on GitHub, don't use the URL of the page you see in the browser (github.com/…/blob/…); use the raw.githubusercontent.com URL you get from the "Raw" button. A blob URL is an HTML page, so passing it directly raises a ParserError (confirmed locally).
If you'd rather save it as a file first, wget works too:
!wget -q -O /content/iris.csv https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv
If you need a whole repository, !git clone https://github.com/username/repository.git clones it into /content.
Download a shared Drive file (gdown)
If someone sends you a Google Drive link shared as "Anyone with the link" can view, you can download it with gdown. In a share link like https://drive.google.com/file/d/FILE_ID/view?usp=sharing, the bold part is the file ID.
!pip install -q gdown # only if it isn't installed
!gdown 1AbCdEfGhIjKlMnOpQrStUvWxYz -O /content/data.csv
From Python:
import gdown
gdown.download(id="1AbCdEfGhIjKlMnOpQrStUvWxYz", output="/content/data.csv")
gdown is an open-source library, not an official Google tool. Older versions needed the --fuzzy option when you passed a share URL, but in the latest version as of December 2026 (6.5) --fuzzy no longer appears in the help, and you simply pass the URL or ID. Passing the file ID works in every version. gdown cannot fetch private files, so use drive.mount() for files in your own Drive.
Read Google Sheets (gspread)
You can read and write spreadsheet data with gspread, using the authentication method from Colab's official sample notebook.
from google.colab import auth
auth.authenticate_user()
import gspread
from google.auth import default
creds, _ = default()
gc = gspread.authorize(creds)
import pandas as pd
sh = gc.open_by_url("https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit")
ws = sh.worksheet("Sheet1")
df = pd.DataFrame(ws.get_all_records()) # use row 1 as column names
df.head()
Running auth.authenticate_user() prompts you to choose an account and grant permissions. get_all_records() treats the first row as headers and returns a list of dictionaries, which you can turn straight into a DataFrame. If the headers are not in the first row, fetch every cell with get_all_values() and reshape it yourself.
Colab also has google.colab.sheets.InteractiveSheet, which embeds an editable spreadsheet in the notebook; sheet.as_df() returns it as a DataFrame.
If the spreadsheet is shared as "Anyone with the link" can view, you can also pass https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/export?format=csv&gid=SHEET_GID to pd.read_csv() as a URL. It needs no authentication, which also means it won't work for private data.
Download or save your results
Download to your computer (files.download)
from google.colab import files
df.to_csv("/content/result.csv", index=False, encoding="utf-8-sig")
files.download("/content/result.csv")
files.download() triggers a browser download. For several files, zip them first and download once:
!zip -r -q /content/outputs.zip /content/outputs
files.download("/content/outputs.zip")
You can also right-click a file name in the Files panel and choose "Download".
Save to Google Drive
With Drive mounted, just save under /content/drive/MyDrive/. The data stays even after the runtime is gone.
import os
out_dir = "/content/drive/MyDrive/ProjectA/outputs"
os.makedirs(out_dir, exist_ok=True)
df.to_csv(f"{out_dir}/result.csv", index=False)
Common errors and fixes
| Error or symptom | Cause | Fix |
|---|---|---|
FileNotFoundError | Wrong path, file lost after a runtime restart, Drive not mounted | Check with !ls. Use "Copy path" in the Files panel |
UnicodeDecodeError: 'utf-8' codec … | Shift_JIS-family CSV | encoding="cp932" |
ParserError: Error tokenizing data | Reading HTML (e.g. a GitHub blob URL), or a different delimiter | Use the raw URL. For TSV, sep="\t" |
| drive.mount timed out | Too many files at the top level of My Drive | Move items into subfolders and empty the trash |
OSError: [Errno 5] Input/output error | Drive quota limits, too many files in one folder | Zip the files and copy them to the VM. Try again later |
When you share an error with someone to ask for help, turning on line numbers in Colab lets you point to the exact line.

