首页 文章

如何在Google Colab中下载pandas Dataframe?

提问于
浏览
2

在Google Colab中创建后,我一直坚持如何将pandas DataFrame下载到我的本地磁盘(或Google Drive) . 我已经尝试将其转换为字节,字符串(使用pd.to_string),dict(pd.to_dict),但似乎没有任何效果 .

另外,我已经看过使用drive.CreateFile方法,如介绍Colab代码中所述,并在此处指定:How to download file created in Colaboratory workspace?,但我不知道如何将其应用于pandas .

任何帮助表示赞赏 - 谢谢!

2 回答

  • 6

    也许是这样的 .

    from google.colab import files
    
    df.to_csv('df.csv')
    files.download('df.csv')
    
  • 1

    对于谷歌colab,我建议使用Pydrive . 你的答案可以在这里找到How to download file created in Colaboratory workspace?

    编辑:只需将filename.csv更改为filename.zip或filename.blabla

    uploaded = drive.CreateFile({'title': 'filename.csv'})
    uploaded.SetContentFile('filename.csv')
    

    为什么?因为这条线

    uploaded.SetContentFile('filename.csv')
    

    内容文件的自动设置格式,因此您无需将其转换为String或Byte .

相关问题