I have one excel file with many sheets. There is only one column in every sheet, which is column A. I plan to read the excel file with read_excel()
method. Hier is the code:
import pandas as PD
ExcelFile = "C:\\AAA.xlsx"
SheetNames = ['0', '1', 'S', 'B', 'U']
# There are five sheets in this excel file. Those are the sheet names.
PageTotal = len(SheetNames)
for Page in range(PageTotal):
df = PD.read_excel(ExcelFile, header=None, squeeze = True, parse_cols = "A" ,sheetname=str(SheetNames[Page]))
print df
#do something with df
The problem is, the for loop
runs only once. By running the second item in the for loop
it shows me the following error text:
File "C:\Python27\lib\site-packages\pandas\io\excel.py", line 170, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Python27\lib\site-packages\pandas\io\excel.py", line 227, in __init__
self.book = xlrd.open_workbook(io)
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 422, in open_workbook
ragged_rows=ragged_rows,
File "C:\Python27\lib\site-packages\xlrd\xlsx.py", line 824, in open_workbook_2007_xml
x12sst.process_stream(zflo, 'SST')
File "C:\Python27\lib\site-packages\xlrd\xlsx.py", line 432, in process_stream_iterparse
for event, elem in ET.iterparse(stream):
File "<string>", line 103, in next
IndexError: pop from empty stack
As a beginner I have no idea about this error. Could anybody please help me to correct the codes? Thanks.
UPDATE Question:If it is because that the excel file contains many formulars and external links, why the for loop
could still run its first item? Confused.