James Draper
James Draper

Reputation: 5310

Is it possible to download an object as a file from google colab WITHOUT first saving it as a file to google drive?

I'm trying to download a pandas dataframe directly from colab's memory INSTEAD of saving that dataframe to drive as a csv then using the files library to download that file.

import pandas as pd
import numpy as np

data = pd.DataFrame(np.random.random(10))

data.to_csv()

This block of code generates a formatted example I just need something that will give me a dialog box so I can save that object locally.

The reason behind this is I'm developing a shared notebook that others will use to generate data and I don't want have the users saving all kinds of stuff to my drive. Is what I'm asking for currently possible?

Upvotes: 0

Views: 971

Answers (1)

Bob Smith
Bob Smith

Reputation: 38639

Yes, there are several options:

  1. Use the google.colab.files module to download like so:
    from google.colab import files
    files.download('csv')
  1. Right click on the file in the file browser and select download like so:

enter image description here

Upvotes: 1

Related Questions