The fastest way to get your table out of Colab

Google Colab runs Python code in your browser, and when you create a table or dataframe there, it stays in Colab unless you download it. The simplest method is to convert your table to a CSV file (a plain-text format that opens in Excel or any spreadsheet program) and download it directly from Colab's file menu. This takes about 30 seconds and requires no extra code.

If your table is already a pandas dataframe — the standard Python object for holding tabular data — you can save it with one line of code. If your table is displayed as HTML or as a formatted output, you have a few options depending on what format you need on your computer.

Key Takeaways

  • The quickest method is to convert your dataframe to CSV using df.to_csv('filename.csv'), then download it from the Files panel on the left side of Colab.
  • CSV files open in Excel, Google Sheets, and any text editor, making them the most portable format for tables.
  • If you need your table as an Excel file instead, use df.to_excel('filename.xlsx') after installing openpyxl with a single pip command.
  • For tables displayed as HTML output, you can right-click the table in Colab and save it, or copy the HTML code and paste it into a text file.
  • Always run your code cell completely before trying to download — Colab only saves files that have been created by executed code.

Download a dataframe as CSV in three steps

This is the method you will use most often. In your Colab cell, type this single line of code after your dataframe is created:

df.to_csv('my_table.csv')

Replace df with whatever you named your dataframe, and replace my_table.csv with whatever filename you want. Run the cell by pressing Ctrl+Enter (or Cmd+Enter on Mac). Colab will create the CSV file in its temporary storage.

Now look at the left side of your Colab window. Click the Files icon (it looks like a folder). You will see a list of files. Find the CSV file you just created, hover over it, and click the three-dot menu that appears. Select "Download". Your browser will download the file to your computer's Downloads folder.

Save as Excel if you need .xlsx format

Excel files (.xlsx) preserve formatting better than CSV and can hold multiple sheets in one file. To save your dataframe as Excel, you need to install a library called openpyxl first. In a new cell, run this line:

pip install openpyxl

Wait for it to finish (you will see "Successfully installed" at the bottom). Then in the next cell, type:

df.to_excel('my_table.xlsx')

Run that cell, then download the file the same way: Files panel on the left, find your .xlsx file, click the three-dot menu, and select Download.

Copy and download HTML tables

If your table is displayed as formatted output in Colab (not stored as a dataframe), you can still get it out. Right-click directly on the table in your notebook and select "Inspect" or "Inspect Element". This opens the browser's developer tools and shows you the HTML code behind the table.

Select all the HTML code (Ctrl+A or Cmd+A), copy it (Ctrl+C or Cmd+C), and paste it into a text editor like Notepad or Google Docs. Save the file with a .html extension (for example, my_table.html). When you open this file in your browser, the table will display with its original formatting.

If you want the data in a spreadsheet instead, you can also try copying the visible table directly: click and drag to select all the cells in the table, copy them, and paste into Excel or Google Sheets. This works for simple tables but may lose formatting on complex ones.

Handle large tables and memory limits

Colab has storage limits. Files you create are temporary and will disappear when your session ends (usually after a few hours of inactivity). Always download your files before closing Colab. If your table is very large (more than a few hundred thousand rows), saving to CSV is faster and uses less memory than Excel.

If you are working with a table so large that Colab runs out of memory, you can save it in chunks. Use the mode='a' parameter in to_csv to append rows instead of writing the whole table at once. This is an advanced technique, but it prevents crashes on massive datasets.

Troubleshooting: File does not appear in the Files panel

The most common reason a file does not show up is that the code cell did not finish running. Look for the spinning circle next to the cell number. Wait until it stops before checking the Files panel.

If the cell finished but the file still is not there, check that you spelled the filename correctly in your code. Also make sure you are looking in the right folder — the Files panel shows the current working directory, which is usually the root of your Colab session.

If you are still stuck, run this line in a new cell to see every file Colab has created:

!ls -la

This will print a list of all files in your current directory. If your file is there but not showing in the Files panel, try refreshing the Files panel by clicking the refresh icon (circular arrow) at the top.

Frequently Asked Questions

Can I download a table directly without writing code?

Not from a dataframe. If your table is displayed as output in Colab, you can right-click it and save as HTML, or select and copy the visible cells to paste into Excel. But to download a dataframe, you need at least one line of code to convert it to a file format.

What is the difference between CSV and Excel?

CSV is plain text and opens in any program, but it does not store formatting, colors, or multiple sheets. Excel (.xlsx) preserves formatting and can hold many sheets in one file, but requires the openpyxl library to create from Colab. For most purposes, CSV is simpler and faster.

Will my file still be there if I close Colab and come back later?

No. Files you create in Colab are temporary and disappear when your session ends. Always download files to your computer before you close Colab. If you need to keep files permanently, save them to Google Drive using Colab's built-in integration.

How do I save multiple tables from one notebook?

Give each table a different filename. For example, df1.to_csv('table_one.csv') and df2.to_csv('table_two.csv'). Then download each file separately from the Files panel. You can also combine multiple dataframes into one Excel file using the sheet_name parameter to put each on a different sheet.

What if my table has special characters or non-English text?

CSV and Excel both handle Unicode text correctly by default. If you open a CSV in Excel and the text looks wrong, try opening it with "Text to Columns" and selecting UTF-8 encoding. This is usually an Excel display issue, not a problem with your file.