我在谷歌的合作实验室 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')
这是错误:
操作系统错误:[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')
关于python - 无法在 Google COLAB 上将我的 Dataframe 保存/导出为 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58636816/