我的输入是:
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.
。
答案 0 :(得分:0)
您当前位于没有写权限的目录中。
使用pwd
检查当前目录。它可能是其中的某个目录的gdrive
,这就是为什么您无法保存在那里的原因。
现在将当前工作目录更改为您有权写入的其他目录。 cd ~
可以正常工作。它将直接引导到/root
。
现在您可以使用:
test.to_csv('submitV1.csv', header=False)
它将'submitV1.csv'
保存到/root