pandas 0.22.0:IndexError:读取xls时列表索引超出范围 [英] Pandas 0.22.0: IndexError: list index out of range when reading xls

查看:399
本文介绍了 pandas 0.22.0:IndexError:读取xls时列表索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将282Mb(65536行x 138列).xls文件加载到熊猫数据框中

I'm trying to load a 282Mb (65536 rows x 138 columns) .xls file into a pandas dataframe

import pandas as pd
import os

filename = r'invoicing.xls'
dir = os.path.dirname(os.path.abspath(filename))
excelFile = os.path.join(dir, filename)
invoicing_info = pd.read_excel(excelFile)

但是我得到了

Traceback (most recent call last):
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/sheet.py", line 698, in put_cell_unragged
    self._cell_types[rowx][colx] = ctype
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/juanda/PycharmProjects/Hyperion_info/load_info.py", line 11, in <module>
    invoicing_info = pd.read_excel(excelFile, sheet_name=0)
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/pandas/util/_decorators.py", line 118, in wrapper
    return func(*args, **kwargs)
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/pandas/io/excel.py", line 230, in read_excel
    io = ExcelFile(io, engine=engine)
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/pandas/io/excel.py", line 294, in __init__
    self.book = xlrd.open_workbook(self._io)
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/__init__.py", line 162, in open_workbook
    ragged_rows=ragged_rows,
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/book.py", line 107, in open_workbook_xls
    bk.fake_globals_get_sheet()
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/book.py", line 728, in fake_globals_get_sheet
    self.get_sheets()
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/book.py", line 719, in get_sheets
    self.get_sheet(sheetno)
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/book.py", line 710, in get_sheet
    sh.read(self)
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/sheet.py", line 1361, in read
    self_put_cell(rowx, colx, None, d, self.fixed_BIFF2_xfindex(cell_attr, rowx, colx))
  File "/Users/juanda/conda_envs/Hyperion_contracts_env/lib/python3.6/site-packages/xlrd/sheet.py", line 709, in put_cell_unragged
    assert 1 <= nr <= self.utter_max_rows
AssertionError

我认为.xls扩展名存在问题,但是在上传之前无法修改文件.如何以可靠的方式上传此.xls文件?

I think this is a problem with the .xls extension but I can't modify the file before uploading it. How can I upload this .xls file in a reliable manner?

推荐答案

我遇到了同样的问题.在将仅值"复制并粘贴到新工作表中之后,将工作表移动(工作表的顺序),现在可以正常工作了.这很烦人.

I was having the same issue. After i copied and pasted "values only" into a new sheet, move the sheet around (order of the sheet), it is working now. This is annoying.

这篇关于 pandas 0.22.0:IndexError:读取xls时列表索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆