gpt4 book ai didi

python - 打开 Excel 文件时出现 Pandas IndexError

转载 作者:太空宇宙 更新时间:2023-11-03 18:24:11 24 4
gpt4 key购买 nike

无论我做什么 - 无论我使用什么 Excel 文件,我都无法打开它们。之前还可以工作...我做什么:

import pandas as pd
xls = pd.ExcelFile('Book1.xls')
xls.parse('Sheet1', index_col=0, na_values=['None'])

或者也

pd.read_excel('Book1.xls', 'Sheet1', index_col=0, na_values=['None'])

我得到了什么:

IndexError                                Traceback (most recent call last)
<ipython-input-35-a09cadf6215b> in <module>()
2 xls = pd.ExcelFile('Book1.xls')
3 #test = xls.parse('SFH', index_col=0, na_values=['None'])
----> 4 pd.read_excel('Book1.xls', 'Sheet1', index_col=0, na_values=['None'])

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/excel.pyc in read_excel(io, sheetname, **kwds)
101 engine = kwds.pop('engine', None)
102
--> 103 return ExcelFile(io, engine=engine).parse(sheetname=sheetname, **kwds)
104
105

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/excel.pyc in parse(self, sheetname, header, skiprows, skip_footer, index_col, parse_cols, parse_dates, date_parser, na_values, thousands, chunksize, convert_float, has_index_names, **kwds)
206 skip_footer=skip_footer,
207 convert_float=convert_float,
--> 208 **kwds)
209
210 def _should_parse(self, i, parse_cols):

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/excel.pyc in _parse_excel(self, sheetname, header, skiprows, skip_footer, index_col, has_index_names, parse_cols, parse_dates, date_parser, na_values, thousands, chunksize, convert_float, **kwds)
302 **kwds)
303
--> 304 return parser.read()
305
306 @property

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/parsers.pyc in read(self, nrows)
624 raise ValueError('skip_footer not supported for iteration')
625
--> 626 ret = self._engine.read(nrows)
627
628 if self.options.get('as_recarray'):

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/parsers.pyc in read(self, rows)
1459
1460 data = self._convert_data(data)
-> 1461 index, columns = self._make_index(data, alldata, columns, indexnamerow)
1462
1463 return index, columns, data

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/parsers.pyc in _make_index(self, data, alldata, columns, indexnamerow)
791
792 elif not self._has_complex_date_col:
--> 793 index = self._get_simple_index(alldata, columns)
794 index = self._agg_index(index)
795

/Users/xy/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/io/parsers.pyc in _get_simple_index(self, data, columns)
834 data.pop(i)
835 if not self._implicit_index:
--> 836 columns.pop(i)
837
838 return index

IndexError: pop from empty list

我做错了什么吗?我应该提交错误报告吗?

最佳答案

确保 Excel 文件的第一不为空...

关于python - 打开 Excel 文件时出现 Pandas IndexError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535149/

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