【发布时间】:2018-03-28 23:57:29
【问题描述】:
我正在尝试确定执行 pandas DataFrame.to_json() 方法时失败的原因。 DataFrame 是有效的,但它非常大(大约 1,000,000 条记录)。
这是我的代码,predictions 是我的 DataFrame:
try:
predictions.to_json(write_file, orient='records', lines=True)
except EOFError as eoferr:
print(eoferr)
sys.exit('\nUnable to write file (%s)! EOFError. Exiting...' % write_file)
except IOError as ioerr:
print(ioerr)
sys.exit('\nUnable to write file (%s)! Permissions problem Exiting...' % write_file)
except Exception as e:
print(e)
sys.exit('\nUnable to write file (%s)! Unknown exception. Exiting...' % write_file)
现在,我收到了 Unknown exception. Exiting... 异常。提前致谢!
【问题讨论】:
-
可以尝试遍历行并在每一行上调用 to_json 吗?
-
谢谢@mobone——我想出了一个解决方法并将其发布为答案。
标签: python json pandas dataframe exception