将私人数据导入谷歌协作笔记本的常用方法是什么?是否可以导入一个非公开的谷歌表?不能从系统文件中读取。介绍性文档链接到使用BigQuery的指南,但这似乎有点…多。


当前回答

您可以通过运行以下命令挂载到谷歌驱动器 从谷歌。Colab导入驱动器 drive.mount(/内容/驱动器) 训练后复制数据从gdrive到colab根文件夹。

cp -r '/content/drive/My drive/ Project_data' '/content'

其中第一个路径是gdrive路径,第二个是colab根文件夹。

这种方法对于大数据的训练速度更快。

其他回答

步骤1-挂载您的谷歌驱动器到协作实验室

from google.colab import drive
drive.mount('/content/gdrive')

第2步-现在你会看到你的谷歌驱动器文件在左侧窗格(文件资源管理器)。右键单击需要导入的文件并选择çopy路径。 然后像往常一样在pandas中导入,使用这个复制的路径。

import pandas as pd
df=pd.read_csv('gdrive/My Drive/data.csv')

完成了!

我创建了一小段代码,可以以多种方式实现这一点。你可以

使用已经上传的文件(在重新启动内核时很有用) 使用来自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()

如果你想在没有代码的情况下做到这一点,这很简单。 把你的文件夹压缩到我的箱子里

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")

在任何协作的左侧栏上都有一个称为“文件”的部分。 在那里上传文件并使用此路径

"/content/YourFileName.extension"

ex: pd read_csv(“/内容/ Forbes2015。csv”);