How to download file created in Colaboratory workspace?

后端 未结 7 1211
攒了一身酷
攒了一身酷 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: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')))
    

提交回复
热议问题