将数据框从Google Collab导出到驱动器(CSV)时出错

时间:2019-10-14 04:37:52

标签: python csv google-colaboratory

我试图将数据框(在这种情况下,我的数据框为df_fdist)保存到我的google驱动器中,所以我运行了这样的代码。

from google.colab import files
df_fdist.to_csv('data.csv') 
files.download('data.csv')

但是,我得到了这个错误。

OSError: [Errno 107] Transport endpoint is not connected

During handling of the above exception, another exception occurred:

我是否需要在驱动器中首先声明任何路径或创建csv文件?

1 个答案:

答案 0 :(得分:0)

要将文件保存到驱动器,必须挂载驱动器

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

将数据框另存为csv

df_fdist.to_csv('/content/drive/My Drive/data.csv')

从驱动器读取

df_myCSV = pd.read_csv('/content/drive/My Drive/data.csv')