Read file from drive in google colab

前端 未结 5 1366
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 06:24

I Have read the notebook about how to open drive. I already did as instructed using:

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


        
5条回答
  •  孤街浪徒
    2021-01-13 07:15

    I ran into a similar issue last night. As some of the previous responders posted there are concerns that influence your ability to read the file. These concerns are, one, making certain that your file is accessible via google drive from your Collab notebook and also, two, making certain that your file is in the correct format.

    I will explain the steps and include a screen shot.

    1. Open Google Collab. Open the File Browser.
    2. Click the icon that says Mount Drive when hovered. This inserts a new cell in your notebook with the code:
    from google.colab import drive
    drive.mount('/content/drive')
    

    Run the cell. You are prompted to accept permissions and get a token to use to mount the drive. Grant the permissions and copy and paste the code into the text input. Hit enter.

    1. The drive now appears in the file browser. Right click the folder /drive/My Drive or click the three dots action menu and select Upload.
    2. Locate your file on disk and Upload.
    3. The file appears in the File Browser. Right click the File (or use the three dots action menu) and select Copy Path.
    4. Paste that file path into your pd.read_csv() call.
    5. Run the cell with the pd.read_csv function call.
    6. You should now have the file uploaded in your Google Drive. Accessible to google collab and file formatting preserved because it not been accessed by any other program to munge the format.

    Below is the example sans Permission tab because I previously granted permissions.

提交回复
热议问题