How to access files on Google Colab notebook

心已入冬 提交于 2019-12-10 11:48:05

问题


How can I access the files on the left bar of Google Colab? By default sample data is given, when I run !ls sample_data command it lists the files as it should:

anscombe.json             mnist_test.csv
california_housing_test.csv   mnist_train_small.csv
california_housing_train.csv  README.md

But when I run following code:

import pandas as pd
data = pd.read_csv('content/sample_data/mnist_test.csv')
print(data.head())

I get an error: FileNotFoundError


回答1:


using upload will place the files under / if you dont move them, so try /PetImages/Dogs/, alternatively you can upload them to google drive and mount your google drive giving access to your files in colab running this in a cell

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

copy over the folder to /content/ using !cp /content/drive/My\ Drive/PetImages.zip /content/ then use !unzip PetImages.zip

now your directory will be /content/PetImages/Dogs/ which might be easier as uploading directory to colab is slower and gets deleted after 12 hours.




回答2:


Are you able to list those files with the command !ls ? Have you already mounted your google drive to colab to access those files? if not, please do so by following the commands mentioned in this blog post



来源:https://stackoverflow.com/questions/54951120/how-to-access-files-on-google-colab-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!