How to download file created in Colaboratory workspace?

后端 未结 7 1183
攒了一身酷
攒了一身酷 2020-12-07 23:55

I found many hints how to upload data into Colaboratory.

But now I want to do opposite -> I want to download .csv I\'ve created in Colaboratory workspace.

Ho

相关标签:
7条回答
  • 2020-12-08 00:35

    Use files colab lib

    from google.colab import files
    files.download('example.txt') 
    

    PS: use chrome browser

    0 讨论(0)
  • 2020-12-08 00:35

    Faced the same issue in downloading csv from colab in Firefox. Here is a quick workaround (worked for me every time and its wierd).

    suppose I have saved a csv like this -

    from google.colab import files
    submission.to_csv('./submission.csv', sep = ',', index = False)
    

    To download this i first do- try downloading some file which doesnt even exist so that colab gives error

    files.download('submission111111.csv')
    

    then run

    files.download('submission.csv')
    

    which is the actual file to download. It works everytime for me and I cant stop laughing to be able to find this wierd trick.

    0 讨论(0)
  • 2020-12-08 00:41

    Here's an extensive tutorial on how to work with files in Google Colab. If you just want to save your data as csv and download it locally:

    from google.colab import files
    
    # e.g. save pandas output as csv
    dataframe.to_csv('example.csv')
    
    # or any other file as usual
    # with open('example.csv', 'w') as f:
    #   f.write('your strings here')
    
    files.download('example.csv')
    
    0 讨论(0)
  • 2020-12-08 00:44

    Save it to google drive use Pydrive

    # Install the PyDrive wrapper & import libraries.
    # This only needs to be done once in a notebook.
    !pip install -U -q PyDrive
    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    from google.colab import auth
    from oauth2client.client import GoogleCredentials
    
    # Authenticate and create the PyDrive client.
    # This only needs to be done once in a notebook.
    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    
    # Create & upload a file.
    uploaded = drive.CreateFile({'title': 'filename.csv'})
    uploaded.SetContentFile('filename.csv')
    uploaded.Upload()
    print('Uploaded file with ID {}'.format(uploaded.get('id')))
    
    0 讨论(0)
  • 2020-12-08 00:44

    Try this ipython functions. !mkdir data && wget http://file_url/file_name.zip && unzip file.zip -d data/

    0 讨论(0)
  • 2020-12-08 00:48

    You can use the file manager panel.

    Use View > Table of contents to show the sidebar then click the Files tab. Right-click the file and select Download.

    Note: the process is unusual in that the download progress is not shown in the usual way in the browser. Instead it is shown by an orange circle next to the file in Colab. Only when the download is complete does it appear in the browser downloads.

    In Firefox, it's best to keep the tab in the foreground while the download is in progress as otherwise it can fail.

    0 讨论(0)
提交回复
热议问题