无法读取 google colaboratory 中的文件。
我在同一目录中有 .ipynb 文件和 .csv 文件,但是当我尝试运行时:
train = pd.read_csv("train.csv")
我得到:
FileNotFoundError: File b'train.csv' does not exist
最佳答案
我希望您在打开 train
之前已经运行了此代码文件。
第一部分# 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()
第三部分# 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}
第四部分# Create a directory and mount Google Drive using that directory.
!mkdir -p drive
!google-drive-ocamlfuse drive
第五部分print ('Files in Drive:')
!ls drive/
执行上述代码后,只需打开您的 train
文件在 google-colaboratory
train = pd.read_csv('drive/...{folder_name}.../train.csv, encoding='utf8')
我希望这有帮助!
关于google-colaboratory - 无法读取 google colaboratory 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48967757/