将私人数据导入谷歌协作笔记本的常用方法是什么?是否可以导入一个非公开的谷歌表?不能从系统文件中读取。介绍性文档链接到使用BigQuery的指南,但这似乎有点…多。
当前回答
在谷歌colabs 如果这是你第一次
from google.colab import drive
drive.mount('/content/drive')
运行这些代码并遍历输出链接 然后穿过传送带到达箱子
复制时,你可以按照下面的方法复制, 转到文件右键单击并复制路径 ***不要忘记删除" /content "
f = open("drive/My Drive/RES/dimeric_force_field/Test/python_read/cropped.pdb", "r")
其他回答
已解决,请在这里找到详细信息,并使用下面的功能: https://stackoverflow.com/questions/47212852/how-to-import-and-read-a-shelve-or-numpy-file-in-google-colaboratory/49467113#49467113
from google.colab import files
import zipfile, io, os
def read_dir_file(case_f):
# author: yasser mustafa, 21 March 2018
# case_f = 0 for uploading one File and case_f = 1 for uploading one Zipped Directory
uploaded = files.upload() # to upload a Full Directory, please Zip it first (use WinZip)
for fn in uploaded.keys():
name = fn #.encode('utf-8')
#print('\nfile after encode', name)
#name = io.BytesIO(uploaded[name])
if case_f == 0: # case of uploading 'One File only'
print('\n file name: ', name)
return name
else: # case of uploading a directory and its subdirectories and files
zfile = zipfile.ZipFile(name, 'r') # unzip the directory
zfile.extractall()
for d in zfile.namelist(): # d = directory
print('\n main directory name: ', d)
return d
print('Done!')
如果你想在没有代码的情况下做到这一点,这很简单。 把你的文件夹压缩到我的箱子里
dataset.zip
然后在Colab中右键单击要放置此文件的文件夹,然后按上传并上传此zip文件。然后写这个Linux命令。
!unzip <your_zip_file_name>
您可以看到您的数据上传成功。
在谷歌colabs 如果这是你第一次
from google.colab import drive
drive.mount('/content/drive')
运行这些代码并遍历输出链接 然后穿过传送带到达箱子
复制时,你可以按照下面的方法复制, 转到文件右键单击并复制路径 ***不要忘记删除" /content "
f = open("drive/My Drive/RES/dimeric_force_field/Test/python_read/cropped.pdb", "r")
一个演示本地文件上传/下载以及与Drive和sheets集成的官方示例笔记本可在这里获得: https://colab.research.google.com/notebooks/io.ipynb
共享文件最简单的方法是挂载您的谷歌驱动器。
要做到这一点,在代码单元格中运行以下命令:
from google.colab import drive
drive.mount('/content/drive')
它会要求您访问一个链接,以允许“谷歌文件流”访问您的驱动器。之后,一个长长的字母数字认证代码将显示,需要输入在你的Colab的笔记本。
之后,您的驱动器文件将被挂载,您可以在侧面板中的文件浏览器浏览它们。
这是一个完整的笔记本示例
你也可以在谷歌上使用我的实现。colab和PyDrive在https://github.com/ruelj2/Google_drive,这使它更容易。
!pip install - U - q PyDrive
import os
os.chdir('/content/')
!git clone https://github.com/ruelj2/Google_drive.git
from Google_drive.handle import Google_drive
Gd = Google_drive()
然后,如果你想加载谷歌驱动器目录中的所有文件,只需
Gd.load_all(local_dir, drive_dir_ID, force=False)
或者只是一个特定的文件
Gd.load_file(local_dir, file_ID)