将私人数据导入谷歌协作笔记本的常用方法是什么?是否可以导入一个非公开的谷歌表?不能从系统文件中读取。介绍性文档链接到使用BigQuery的指南,但这似乎有点…多。
当前回答
你也可以在谷歌上使用我的实现。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)
其他回答
快速,简单地从Dropbox导入:
!pip install dropbox
import dropbox
access_token = 'YOUR_ACCESS_TOKEN_HERE' # https://www.dropbox.com/developers/apps
dbx = dropbox.Dropbox(access_token)
# response = dbx.files_list_folder("")
metadata, res = dbx.files_download('/dataframe.pickle2')
with open('dataframe.pickle2', "wb") as f:
f.write(res.content)
在任何协作的左侧栏上都有一个称为“文件”的部分。 在那里上传文件并使用此路径
"/content/YourFileName.extension"
ex: pd read_csv(“/内容/ Forbes2015。csv”);
在Colab中只有两行代码。非常简单的方法:
将您的所有文件装入一个压缩档案谷歌驱动器。 通过链接让每个人都能看到。 从这个链接复制ID。(例如:在这个链接中https://drive.google.com/open?id=29PGh8XCts3mlMP6zRphvnIcbv27boawn ID是29PGh8XCts3mlMP6zRphvnIcbv27boawn) 进入Colab: !gdown——id 29pgh8xcts3mlmp6zrphvnicbv27bown 最后一步进入Colab: ! 解压缩file_name.zip
瞧!Colab中/content/file_name.csv中所有需要的文件都已准备就绪
对于这个简单的方法从驱动器到Colab,我感谢Gleb Mikhaylov。
我创建了一小段代码,可以以多种方式实现这一点。你可以
使用已经上传的文件(在重新启动内核时很有用) 使用来自Github的文件 手动上传文件
import os.path
filename = "your_file_name.csv"
if os.path.isfile(filename):
print("File already exists. Will reuse the same ...")
else:
use_github_data = False # Set this to True if you want to download from Github
if use_github_data:
print("Loading fie from Github ...")
# Change the link below to the file on the repo
filename = "https://github.com/ngupta23/repo_name/blob/master/your_file_name.csv"
else:
print("Please upload your file to Colab ...")
from google.colab import files
uploaded = files.upload()
上传数据/导入数据到谷歌colab GUI方式的最佳和简单的方法是点击左边的第3个选项文件菜单图标,在那里你会得到上传浏览器文件,因为你在windows操作系统。检查下面的图像更好地容易理解。点击下面两个选项后,你会很容易地得到上传窗口框。工作。
from google.colab import files
files=files.upload()