接下来我们要读取数据了,
首先挂载google drive:
# Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
然后读取我们的内容,
txt格式:
file = drive.CreateFile({'id': '你的文件id'})
file.GetContentFile('你的文件名.txt',"text/plain")
csv格式:
file = drive.CreateFile({'id': '你的文件id