Load local data files to Colaboratory

后端 未结 9 757
野趣味
野趣味 2020-12-02 08:47

I just wondering that is it possible to load local data files(like .xlsx or .csv files that on my google drive) into Colaboratory?

9条回答
  •  悲&欢浪女
    2020-12-02 09:15

    Say, You have a folder on your Google drive named Colab and a csv is file located there. To load this file

    import pandas as pd
    titanic = pd.read_csv(“drive/Colab/Titanic.csv”)
    titanic.head(5)
    

    Before that, you may need to run these command:

    Run these codes first in order to install the necessary libraries and perform authorization.

    !apt-get install -y -qq software-properties-common python-software-properties module-init-tools
    !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
    !apt-get update -qq 2>&1 > /dev/null
    !apt-get -y install -qq google-drive-ocamlfuse fuse
    from google.colab import auth
    auth.authenticate_user()
    from oauth2client.client import GoogleCredentials
    creds = GoogleCredentials.get_application_default()
    import getpass
    !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
    vcode = getpass.getpass()
    !echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
    

    When you run the code above, you should see a result like this:

    Click the link, copy verification code and paste it to text box.

    After completion of the authorization process,

    mount your Google Drive:

    !mkdir -p drive
    !google-drive-ocamlfuse drive
    

提交回复
热议问题