Closed
Description
df = pd.read_excel(r'\\path_to_Excel_file',
'Sheet1', parse_cols=['MODEL_YEAR'])
returns:
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-29-336e4fd9eea1> in <module>()
4
5 df = pd.read_excel(r'\\path_to_Excel_file',
----> 6 'Sheet1', parse_cols=["MODEL_YEAR"])
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\excel.py in read_excel(io, sheetname, **kwds)
125 engine = kwds.pop('engine', None)
126
--> 127 return ExcelFile(io, engine=engine).parse(sheetname=sheetname, **kwds)
128
129
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\excel.py 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)
236 skip_footer=skip_footer,
237 convert_float=convert_float,
--> 238 **kwds)
239
240 def _should_parse(self, i, parse_cols):
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\excel.py 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)
355 skip_footer=skip_footer,
356 chunksize=chunksize,
--> 357 **kwds)
358
359 return parser.read()
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in TextParser(*args, **kwds)
1285 """
1286 kwds['engine'] = 'python'
-> 1287 return TextFileReader(*args, **kwds)
1288
1289
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds)
555 self.options['has_index_names'] = kwds['has_index_names']
556
--> 557 self._make_engine(self.engine)
558
559 def _get_options_with_defaults(self, engine):
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
698 elif engine == 'python-fwf':
699 klass = FixedWidthFieldParser
--> 700 self._engine = klass(self.f, **self.options)
701
702 def _failover_to_python(self):
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in __init__(self, f, **kwds)
1392 # infer column indices from self.usecols if is is specified.
1393 self._col_indices = None
-> 1394 self.columns, self.num_original_columns = self._infer_columns()
1395
1396 # Now self.columns has the set of columns that we will process.
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in _infer_columns(self)
1607 columns = []
1608 for level, hr in enumerate(header):
-> 1609 line = self._buffered_line()
1610
1611 while self.line_pos <= hr:
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in _buffered_line(self)
1734 return self.buf[0]
1735 else:
-> 1736 return self._next_line()
1737
1738 def _empty(self, line):
D:\Miniconda3\envs\notebook\lib\site-packages\pandas\io\parsers.py in _next_line(self)
1758 break
1759 except IndexError:
-> 1760 raise StopIteration
1761 else:
1762 while self.pos in self.skiprows:
StopIteration:
Documentation says the following:
parse_cols : int or list, default None
- If None then parse all columns
- If int then indicates last column to be parsed
- If list of ints then indicates list of column numbers to be parsed
- If string then indicates comma separated list of column names and column ranges (e.g. “A:E” or “A,C,E:F”)
Also did:
df = pd.read_excel(r'\\path_to_Excel_file',
'Sheet1', parse_cols="MODEL_YEAR")
But still got the same error.
Using Windows 7 with Miniconda3
conda list output:
beautiful-soup 4.3.2 py34_0
beautifulsoup4 4.3.2 <pip>
brewer2mpl 1.4.1 <pip>
dateutil 2.1 py34_2
ggplot 0.6.5 <pip>
ipython 2.3.1 py34_0
jdcal 1.0 py34_0
jinja2 2.7.3 py34_1
lxml 3.4.0 py34_0
markupsafe 0.23 py34_0
matplotlib 1.4.2 np19py34_0
numexpr 2.3.1 np19py34_0
numpy 1.9.1 py34_0
openpyxl 2.0.2 py34_0
pandas 0.15.1 np19py34_0
patsy 0.3.0 np19py34_0
pip 1.5.6 py34_0
pycrypto 2.6.1 py34_2
pygments 2.0.1 py34_0
pyodbc 3.0.7 py34_0
pyparsing 2.0.1 py34_0
pyqt 4.10.4 py34_0
pyreadline 2.0 py34_0
python 3.4.2 0
python-dateutil 2.1 <pip>
pytz 2014.9 py34_0
pywin32 219 py34_0
pyzmq 14.4.1 py34_0
requests 2.4.3 py34_0
scipy 0.14.0 np19py34_0
seaborn 0.5.0 <pip>
setuptools 7.0 py34_0
six 1.8.0 py34_0
statsmodels 0.6.0 np19py34_0
tornado 4.0.2 py34_0
xlrd 0.9.3 py34_0