![](/img/trans.png)
[英]Export dataframe as csv file from google colab to google drive
[英]Cant save / Export my Dataframe to CSV on Google's COLAB
我在谷歌的合作实验室 COLAB 中有一个 Panda Dataframe。 我正在尝试将它作为 CSV 文件导出到我的 GoogleDrive,但它不起作用。 这是我使用的代码:
d = {'col1': [1, 2], 'col2': [3, 4]}
MyDF = pd.DataFrame(data=d)
from google.colab import drive
drive.mount('/content/drive')
此时,我收到消息:
Mounted at /content/drive
然后我继续:
MyDF.to_csv('content/drive/My Drive/MyFolders/MyDF.csv')
这是错误:
OSError:[Errno 107] 传输端点未连接:'/gdrive'
我将它与不同的浏览器一起使用,包括 Chrome,但并没有什么不同。 我不确定是什么问题。 我愿意接受任何可以帮助我将 DataFrame 导出为 gdrive 或本地文件的解决方案。
谢谢!!
感谢@Roozeppe 和@Trenton McKinney。 这对我有用:
# Mounting the gdrive
from google.colab import drive
drive.mount('/content/drive')
# getting a list of Directories show I am not where I should be
ls
“我的驱动器”/
# Changing the working Directory to Where I want to Export.
# The space in 'My Drive' Name didn't create any issues.
%cd /gdrive/My Drive/PythonExports
# Exporting MyDf dataframe
MyDF.to_csv('MyDF.csv')
从目录中删除content/
MyDF.to_csv('content/drive/My Drive/MyFolders/MyDF.csv')
变成
MyDF.to_csv('drive/My Drive/MyFolders/MyDF.csv')
通过运行pwd
检查您的工作目录。 除非您更改它,否则它应该是/content
,默认值。 假设它是默认值,只需运行MyDF.to_csv('drive/My Drive/MyFolders/MyDF.csv')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.