Can't read a file in google colaboratory

后端 未结 4 704
广开言路
广开言路 2021-02-02 17:12

Can\'t read a file in google colaboratory . I have .ipynb file and .csv files in the same directory but when I try to run:

train = pd.read_csv(\"train.csv\") 
<         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 17:24

    I hope you have run this code before opening your train file.

    Part I

    # Install a Drive FUSE wrapper. # https://github.com/astrada/google-drive-ocamlfuse !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

    Part II

    # Generate auth tokens for Colab

    from google.colab import auth auth.authenticate_user()

    Part III

    # Generate creds for the Drive FUSE library.

    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}

    Part IV

    # Create a directory and mount Google Drive using that directory.

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

    Part V

    print ('Files in Drive:') !ls drive/

    After implementing the above codes just open your train file in google-colaboratory

    train = pd.read_csv('drive/...{folder_name}.../train.csv, encoding='utf8')

    I hope this helps!

提交回复
热议问题