【问题标题】:Error saving files into google drive via google colab通过 google colab 将文件保存到 google 驱动器时出错
【发布时间】:2020-03-29 10:25:58
【问题描述】:

我正在尝试将文件从 colab 笔记本保存到我的 Google 云端硬盘,但我不断收到相同的错误。我已经安装了我的驱动器。当我调用 pwd 时,我得到了,这似乎是正确的:

/content/drive/My Drive/

这是一个示例代码和读出:

from google.colab import drive
drive.mount('/content/drive')
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
print(df)
df.to_csv('test.csv')

         A   B   C   D
    0   38  28  18  74
    1   36  54  84  13
    2    2   1  55  42
    3   69  20  15  40
    4   83  58  81  76
    ..  ..  ..  ..  ..
    95  92  65   3  50
    96  25  15  82  84
    97  60  24  29  10
    98  13  26  94  25
    99  46  36  91  24

    [100 rows x 4 columns]
    ---------------------------------------------------------------------------
    OSError                                   Traceback (most recent call last)
    <ipython-input-10-d5c5784f87b6> in <module>()
          4 df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
          5 print(df)
    ----> 6 df.to_csv('test.csv')

    2 frames
    /usr/local/lib/python3.6/dist-packages/pandas/io/common.py in _get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text)
        397         if encoding:
        398             # Encoding
    --> 399             f = open(path_or_buf, mode, encoding=encoding, newline="")
        400         elif is_text:
        401             # No explicit encoding

    OSError: [Errno 30] Read-only file system: 'test.csv'





【问题讨论】:

    标签: python pandas google-drive-api google-colaboratory


    【解决方案1】:

    你想保存到谷歌驱动,你应该添加挂载路径:

    from google.colab import drive
    drive.mount('/content/drive')
    import pandas as pd
    import numpy as np
    
    df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
    print(df)
    df.to_csv('/content/drive/My Drive/test.csv')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2022-01-27
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      相关资源
      最近更新 更多