Python 如何使用Colaboratory(谷歌)从谷歌硬盘读取数据
我是Colaboratory的新手,我想在我的谷歌硬盘上安装一个小项目。在我的谷歌硬盘上,我创建了一个文件夹“TheProject”,在那里我创建了两个文件夹:“code”和“data”。我创建了一个新的colab笔记本,在“数据”文件夹中有几个数据集 问题 如何将数据从谷歌硬盘上的文件夹读入colab笔记本? 例如:Python 如何使用Colaboratory(谷歌)从谷歌硬盘读取数据,python,google-drive-api,jupyter-notebook,Python,Google Drive Api,Jupyter Notebook,我是Colaboratory的新手,我想在我的谷歌硬盘上安装一个小项目。在我的谷歌硬盘上,我创建了一个文件夹“TheProject”,在那里我创建了两个文件夹:“code”和“data”。我创建了一个新的colab笔记本,在“数据”文件夹中有几个数据集 问题 如何将数据从谷歌硬盘上的文件夹读入colab笔记本? 例如: data = pd.read_excel('SOME_PATH/TheProject/data/my_data.xlsx') 其中某些路径应指明如何进入主文件夹“TheProj
data = pd.read_excel('SOME_PATH/TheProject/data/my_data.xlsx')
其中
某些路径应指明如何进入主文件夹“TheProject”并从“data”文件夹读取数据。右键单击Google Drive上的文件并获取其可共享链接。您将从该链接提取文件id
! pip install pydrive
# these classes allow you to request the Google drive API
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
file_id = '<your_file_id>'
downloaded = drive.CreateFile({'id': file_id})
# allows you to temporarily load your file in the notebook VM
# assume the file is called file.csv and it's located at the root of your drive
downloaded.GetContentFile('file.csv')
布拉沃·艾哈迈德:):)
data = pd.read_csv('file.csv')