如何从Google Colab中的Google驱动器访问文件

时间:2020-01-14 04:28:46

标签: google-colaboratory

我正在尝试从Google驱动器中读取数据,但是却显示找不到文件的错误

我使用下面的代码片段进行了尝试:

# Load the Drive helper and mount
from google.colab import drive

# This will prompt for authorization.
drive.mount('/content/drive')

from pandas import read_hdf
df_final_train = read_hdf('FB_data/storage_sample_stage5.h5', 'train_df',mode='r')
df_final_test = read_hdf('FB_data/storage_sample_stage5.h5', 'test_df',mode='r')

错误是

FileNotFoundError Traceback(最近一次通话) 在()中 1从熊猫导入read_hdf ----> 2 df_final_train = read_hdf('FB_data / storage_sample_stage5.h5','train_df',mode ='r') 3 df_final_test = read_hdf('FB_data / storage_sample_stage5.h5','test_df',mode ='r')

/usr/local/lib/python3.6/dist-packages/pandas/io/pytables.py在read_hdf中(path_or_buf,key,mode,** kwargs) 379(如果不存在): 第380章; -> 381“文件{path}不存在” .format(path = path_or_buf) 382) 383

FileNotFoundError:文件FB_data / storage_sample_stage5.h5不存在

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

/content/drive不是工作目录。

使用%cd将工作目录更改为您的云端硬盘根目录。或者,在read_hdf的参数中使用绝对路径。