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
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
We can use the pandas module read_excel() function to read the excel file data into a DataFrame object. If you look at an excel sheet, it's a two-dimensional table. The DataFrame object also represents a two-dimensional tabular data structure.
The read_excel() method from the pandas library reads excel files, that is, files in the . xls format. It takes the file name or directory as the first argument with the sheet name as the second argument value. As a matter of course, it takes an excel file as input and returns it as a DataFrame.
Read an Excel file into a pandas DataFrame. Supports xls , xlsx , xlsm , xlsb , odf , ods and odt file extensions read from a local filesystem or URL. Supports an option to read a single sheet or a list of sheets.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With