F1s*_*her 28 google-colaboratory
我发现了很多关于如何将数据上传到Colaboratory的提示.
但现在我想做相反的事情 - >我想下载.csv我在Colaboratory工作区创建.
这该怎么做?
nid*_*hin 96
使用文件colab lib
from google.colab import files
files.download('example.txt')
Run Code Online (Sandbox Code Playgroud)
PS:使用chrome浏览器
Tam*_*lyn 47
您可以使用文件管理器面板.
右键单击该文件,然后选择"下载".它只允许您查看当前文件夹(和后代),但如果您想要其他地方的文件,您可以先将其复制到当前文件夹中,其中包含一个shell单元格:
__PRE__
Moh*_*had 12
保存到谷歌驱动器使用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')))
Run Code Online (Sandbox Code Playgroud)
Ayu*_*ain 11
您需要添加这两行:
from google.colab import files
files.download('file.txt')
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 Firefox,那么这可能不起作用。为了使这项工作:
现在,它将下载。这是我同事告诉的一个hacky解决方案。我不知道它为什么有效!如果你知道为什么,请评论它。
有一种更干净、更简单的方法可以在 Firefox 和 chrome 中使用。
单击 > 图标。单击文件。它将显示笔记本中的所有文件和文件夹。左键单击要下载的文件,选择下载即可。此过程也可应用于上传文件/文件夹。对于上传文件夹,您必须先将其压缩。
下面是一个广泛的教程就如何在谷歌Colab文件。如果您只想将数据另存为csv并在本地下载:
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')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36440 次 |
| 最近记录: |