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


当前回答

如果数据集大小小于25mb,最简单的方法是从你的GitHub存储库上传CSV文件。

单击存储库中的数据集 点击“查看原始”按钮 复制链接并将其存储在一个变量中 将变量加载到Pandas read_csv中以获得数据帧

例子:

import pandas as pd
url = 'copied_raw_data_link'
df1 = pd.read_csv(url)
df1.head()

其他回答

对于那些像我一样从谷歌搜索关键字“上传文件colab”的人:

from google.colab import files
uploaded = files.upload()

快速,简单地从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)

正如@Vivek Solanki所提到的,我也在协作仪表板的“文件”部分上传了我的文件。 只需要注意文件上传的位置。对我来说, train_data = pd.read_csv('/fileName.csv')有效。

如果数据集大小小于25mb,最简单的方法是从你的GitHub存储库上传CSV文件。

单击存储库中的数据集 点击“查看原始”按钮 复制链接并将其存储在一个变量中 将变量加载到Pandas read_csv中以获得数据帧

例子:

import pandas as pd
url = 'copied_raw_data_link'
df1 = pd.read_csv(url)
df1.head()

已解决,请在这里找到详细信息,并使用下面的功能: 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!')