【问题标题】:What is OSError: [Errno 95] Operation not supported for pandas to_csv on colab?什么是 OSError:[Errno 95] Colab 上的 pandas to_csv 不支持操作?
【发布时间】:2019-06-15 09:20:29
【问题描述】:

我的输入是:

test=pd.read_csv("/gdrive/My Drive/data-kaggle/sample_submission.csv")
test.head()

它按预期运行。 但是,对于

test.to_csv('submitV1.csv', header=False)

我收到的完整错误消息是:

OSError    Traceback (most recent call last)
<ipython-input-5-fde243a009c0> in <module>()
9 from google.colab import files
10 print(test)'''
---> 11 test.to_csv('submitV1.csv', header=False)
12 files.download('/gdrive/My Drive/data- 
kaggle/submission/submitV1.csv')

2 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in 
to_csv(self, path_or_buf, sep, na_rep, float_format, columns, 
header, index, index_label, mode, encoding, compression, quoting, 
quotechar, line_terminator, chunksize, tupleize_cols, date_format, 
doublequote, escapechar, decimal)
3018                                  doublequote=doublequote,
3019                                  escapechar=escapechar, 
decimal=decimal)
-> 3020         formatter.save()
3021 
3022         if path_or_buf is None:

 /usr/local/lib/python3.6/dist-packages/pandas/io/formats/csvs.pyi 
 in save(self)
 155             f, handles = _get_handle(self.path_or_buf, 
 self.mode,
 156                                      encoding=self.encoding,
 --> 157                                      
 compression=self.compression)
 158             close = True
 159 

 /usr/local/lib/python3.6/dist-packages/pandas/io/common.py in 
 _get_handle(path_or_buf, mode, encoding, compression, memory_map, 
 is_text)
 422         elif encoding:
 423             # Python 3 and encoding
 --> 424             f = open(path_or_buf, mode,encoding=encoding, 
 newline="")
 425         elif is_text:
 426             # Python 3 and no explicit encoding

 OSError: [Errno 95] Operation not supported: 'submitV1.csv'

有关错误的其他信息: 在运行此命令之前,如果我运行

df=pd.DataFrame()
df.to_csv("file.csv")
files.download("file.csv")

它运行正常,但是如果我在尝试将测试数据帧转换为 csv 文件后尝试运行相同的代码,则会产生操作不支持的错误。

在运行命令之前,我还会收到一条消息 A Google Drive timeout has occurred (most recently at 13:02:43). More info.

【问题讨论】:

    标签: pandas export-to-csv


    【解决方案1】:

    您当前位于您没有写入权限的目录中。

    使用pwd 检查您的当前目录。它可能是其中某个目录的gdrive,这就是您无法保存在那里的原因。

    现在将当前工作目录更改为您有权写入的其他目录。 cd ~ 可以正常工作。它会将目录更改为/root。 现在您可以使用:

    test.to_csv('submitV1.csv', header=False)

    它将'submitV1.csv'保存到/root

    【讨论】:

      猜你喜欢
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-05
      • 2020-12-19
      • 2023-02-13
      • 2018-04-25
      • 1970-01-01
      相关资源
      最近更新 更多