首页 文章

在Google colaboratory笔记本中找不到Csv文件错误

提问于
浏览
3

我正在尝试将存储在google驱动器中的csv文件加载到colab笔记本中 . 当我尝试加载文件时,它显示“找不到文件” . 将存储在google驱动器中的文件加载到colab笔记本的过程是什么?

1 回答

  • 3

    要从Google Cloud 端硬盘访问文件,您需要使用PyDrive或Drive Rest API加载文件 .

    在访问文件之前运行以下代码

    !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
    
    # 1. Authenticate and create the PyDrive client.
    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    
    # 2. Load a file by ID and create local file.
    downloaded = drive.CreateFile({'id':'fileid'}) # replace fileid with Id of file you want to access
    downloaded.GetContentFile('export.csv') # now you can use export.csv
    

相关问题