无法在Google colaboratory中读取文件 [英] Can't read a file in google colaboratory

查看:316
本文介绍了无法在Google colaboratory中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在google colaboratory中读取文件. 我在同一目录中有.ipynb文件和.csv文件,但是当我尝试运行时:

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") 

我得到:

FileNotFoundError: File b'train.csv' does not exist

推荐答案

我希望您在打开train文件之前已运行此代码.

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

# 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

# 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

# Generate auth tokens for Colab

from google.colab import auth auth.authenticate_user()

from google.colab import auth auth.authenticate_user()

# 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}

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}

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

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

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

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

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

实施上述代码后,只需在google-colaboratory

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

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

我希望这会有所帮助!

这篇关于无法在Google colaboratory中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆