pandas 0.19.2 read_excel IndexError:列表索引超出范围 [英] Pandas 0.19.2 read_excel IndexError: List index out of range

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

问题描述

我想解析一个Excel电子表格.我决定使用熊猫,但立即被错误发现.

I am looking to parse an excel spreadsheet. I decided to use pandas but got caught by an error straight off the bat.

我从下面的代码开始,但是尝试使用完整路径,并尝试设置工作表名称.

I started with the code below but played around with using a full path and also tried setting the sheetname.

import pandas as pd

table = pd.read_excel('ss_12.xlsx')

if __name__ == '__main__':
    pass

excel电子表格与我的脚本文件位于同一目录中.我教过它在这种意义上与open()相同,只是在同一个目录中需要一个名称.我在网上查看了一些示例,通过它们可以正常工作.

The excel spreadsheet is in the same directory as my script file. I taught it would work the same as open() in this sense, just a name required if its in the same directory. I have looked at a few examples online and going by them this should work.

我正在尝试删除上图中的第一列.完整错误(不确定如何格式化,抱歉)

I am trying to strip the first column seen in the image above. The full error (not sure how to format it, sorry)

C:\xx\Playpen\ConfigList_V1_0.xlsx
Traceback (most recent call last):
  File "C:\xx\Playpen\getConVars.py", line 12, in <module>
    pd.read_excel(excelFile)
  File "C:\xx\Programs\Python\Python35\lib\site-packages\pandas\io\excel.py", line 200, in read_excel
    **kwds)
  File "C:\xx\Programs\Python\Python35\lib\site-packages\pandas\io\excel.py", line 432, in _parse_excel
    sheet = self.book.sheet_by_index(asheetname)
  File "C:\xx\Programs\Python\Python35\lib\site-packages\xlrd\book.py", line 432, in sheet_by_index
    return self._sheet_list[sheetx] or self.get_sheet(sheetx)
IndexError: list index out of range

推荐答案

请确保您具有正确的Excel电子表格.我遇到了同样的错误,并意识到我已将其保存为仍然具有.xlsx扩展名的Strict XML Open Spreadsheet.

Make sure you have the right kind of Excel spreadsheet. I had this same error and realized that I had saved it as a Strict XML Open Spreadsheet which still had the .xlsx extension.

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

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