python - 无法在 Google COLAB 上将我的 Dataframe 保存/导出为 CSV

标签 python pandas tensorflow cloud google-colaboratory

我在谷歌的合作实验室 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/

相关文章:

python - 使用 selenium 和 python 选择下拉菜单时遇到问题

python - 如何将带有字数统计的列表转换为字典

python - 对数据框中第二列的每个值计算一列的值

python - 使用 pandas 将 CSV 列读取为分类变量

python - 复制 xpath 未提供正确的 xpath?

python - 在 pd.DataFrame 中插入一行而不加载文件

python - keras多层LSTM模型的股价预测收敛于恒定值

python - Tensorflow:具有交叉熵损失的加权稀疏 softmax

python - 使用 tf.optimizers.Adam.minimize() 时,对象不可调用

python - Jenkins 构建返回 'None' 状态