Pandas有时写空的或损坏的文件

2024-04-26 23:21:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我用熊猫已经有一段时间了,我认为它是一个很好的工具。我制作了一个程序,从用户收集的一些数据中生成一些excel文件。最终用户已经测试并使用了6个月;直到昨天,它生成了一个dagamaged excel文件才失败。当我用文本编辑器打开它时,它完全是空白的。生成此文件的代码如下:

        escritor = pandas.ExcelWriter(direccion, engine='xlsxwriter')
        listaTotal.to_excel(escritor, index = False)
        escritor.save()

以及:

^{pr2}$

第二个代码片段还为“xlsxwriter”使用了一些格式选项,示例如下:

^{3}$

这个错误发生了两次,大约是1个月前和昨天。我不能重复这个错误,我不知道发生了什么。这里还有回溯,它显示了程序读取文件时的问题,但是这个文件是由之前发布的代码生成的:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1532, in __call__
    return self.func(*args)
  File "C:\Users\WINNER\Documents\Visual Studio 2013\Projects\PythonApplication4\PythonApplication4\PythonApplication4.py", line 792, in botonGenerarPedido
    self.generarPedido()
  File "C:\Users\WINNER\Documents\Visual Studio 2013\Projects\PythonApplication4\PythonApplication4\PythonApplication4.py", line 904, in generarPedido
    self.generarVentasDia()
  File "C:\Users\WINNER\Documents\Visual Studio 2013\Projects\PythonApplication4\PythonApplication4\PythonApplication4.py", line 927, in generarVentasDia
    listaTotal = pandas.io.excel.read_excel(direccion)
  File "C:\Python27\lib\site-packages\pandas\io\excel.py", line 151, in read_excel
    return ExcelFile(io, engine=engine).parse(sheetname=sheetname, **kwds)
  File "C:\Python27\lib\site-packages\pandas\io\excel.py", line 188, in __init__
    self.book = xlrd.open_workbook(io)
  File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 435, in open_workbook
    ragged_rows=ragged_rows,
  File "C:\Python27\lib\site-packages\xlrd\book.py", line 91, in open_workbook_xls
    biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
  File "C:\Python27\lib\site-packages\xlrd\book.py", line 1230, in getbof
    bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8])
  File "C:\Python27\lib\site-packages\xlrd\book.py", line 1224, in bof_error
    raise XLRDError('Unsupported format, or corrupt file: ' + msg)
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found '\x00\x00\x00\x00\x00\x00\x00\x00'

Tags: 文件inpyioselflibpackagesline