gpt4 book ai didi

Python不执行写命令

转载 作者:行者123 更新时间:2023-11-28 18:35:19 25 4
gpt4 key购买 nike

Python没有完成下面的功能(使用iPython Notebook和Graphlab)

def print_submission_file(var, filename='submission.txt'):
with open(filename, 'w') as f:
f.write('Id,Sales\n')
for row in var:
f.write(str(row['Id']) + ',' + str(row['Prediction']) + '\n')

print_submission_file(test, 'submission.txt')

这是脚本停止时的日志(5/10 分钟后)

---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-9-f51bf8359fb9> in <module>()
5 f.write(str(row['Id']) + ',' + str(row['Prediction']) + '\n')
6
----> 7 print_submission_file(test, 'submission.txt')

<ipython-input-9-f51bf8359fb9> in print_submission_file(var, filename)
2 with open(filename, 'w') as f:
3 f.write('Id,Sales\n')
----> 4 for row in var:
5 f.write(str(row['Id']) + ',' + str(row['Prediction']) + '\n')
6

/Users/MaximeDeBruyn/.graphlab/anaconda/lib/python2.7/site-packages/graphlab/data_structures/sframe.pyc in generator()
3694 def generator():
3695 elems_at_a_time = 262144
-> 3696 self.__proxy__.begin_iterator()
3697 ret = self.__proxy__.iterator_get_next(elems_at_a_time)
3698 column_names = self.column_names()

graphlab/cython/cy_sframe.pyx in graphlab.cython.cy_sframe.UnitySFrameProxy.begin_iterator()

graphlab/cython/cy_sframe.pyx in graphlab.cython.cy_sframe.UnitySFrameProxy.begin_iterator()

RuntimeError: Runtime Exception. Canceled by user

因此该函数在 submission.txt 中写入“Id,Sales”但从未完成 for 循环...感谢您的帮助。我真的不知道该怎么办。

最佳答案

您的循环可能只需要很长时间以这种方式迭代 SFrame。错误消息是因为您使用 Ctrl-C 取消了命令(我猜)。

如果你想写一个只有这两列的 csv,试试这个(假设 var 是一个 SFrame):

var[['Id','Prediction']].save("submission", format="csv")

关于Python不执行写命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33063907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com