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


当前回答

从谷歌。Colab导入驱动器

驱动器(' /内容/ drive’山)

进口熊猫作为pd dv = pd.read_csv(' /内容/传动/ MyDrive /戴安娜/卡索/ Data_Caso_Propuesto.csv”) dv.info ()

其他回答

步骤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')

完成了!

你也可以在谷歌上使用我的实现。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)

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

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

一个演示本地文件上传/下载以及与Drive和sheets集成的官方示例笔记本可在这里获得: https://colab.research.google.com/notebooks/io.ipynb

共享文件最简单的方法是挂载您的谷歌驱动器。

要做到这一点,在代码单元格中运行以下命令:

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

它会要求您访问一个链接,以允许“谷歌文件流”访问您的驱动器。之后,一个长长的字母数字认证代码将显示,需要输入在你的Colab的笔记本。

之后,您的驱动器文件将被挂载,您可以在侧面板中的文件浏览器浏览它们。

这是一个完整的笔记本示例

在谷歌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")