Create a file download link to a dynamically generated file in Google Colab jupyter notebooks

2.8k views Asked by At

How do you get FileLink(filename) to work in Google Colab in order to generate a download link? Is there a better way than FileLink?

Right now this code generates a download link pointing to localhost:

import pandas as pd
from IPython.display import FileLink, FileLinks

df = pd.DataFrame([[1,2,3],[4,5,6]])
df.to_csv('mydf.csv', index=False)
FileLink('mydf.csv')

The link generated as output points to: https://localhost:8080/myfile.csv

How do I get it to point to the correct file?

1

There are 1 answers

1
Bob Smith On

Try:

from google.colab import files
files.download('mydf.csv')

Or, more simply, use the file browser in the left hand pane.

enter image description here