在Python xlrd中读取Excel文件

我真的很努力阅读一个Python中的excel文件,这是我需要能够做的课程,我已经设置,我已经find了一个使用xlrd做的方法,但是,我不能得到它的工作。 我用cmd来安装xlrd(pip install xlrd),但是成功,但是我仍然无法读取Excel工作表到Python,我不确定为什么它不工作,下面是我的代码:

import xlrd file_location = "C:/Users/Sean/Desktop/DADSA 17-18 COURSEWORK A MALE PLAYERS.csv" workbook = xlrd.open_workbook(file_location) 

现在,我看过这个方法的每个教程都起作用了,但是当我尝试这样做时,我得到一个错误:

 "Traceback (most recent call last): File "C:\Users\Sean\Desktop\Data Structures Assignment 1\Tennis.py", line 3, in <module> workbook = xlrd.open_workbook(file_location) File "C:\Users\Sean\lib\site-packages\xlrd\__init__.py", line 162, in open_workbook ragged_rows=ragged_rows, File "C:\Users\Sean\lib\site-packages\xlrd\book.py", line 91, in open_workbook_xls biff_version = bk.getbof(XL_WORKBOOK_GLOBALS) File "C:\Users\Sean\lib\site-packages\xlrd\book.py", line 1271, in getbof bof_error('Expected BOF record; found %r' % self.mem[savpos:savpos+8]) File "C:\Users\Sean\lib\site-packages\xlrd\book.py", line 1265, in bof_error raise XLRDError('Unsupported format, or corrupt file: ' + msg) xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'MP01\r\nMP'" 

任何帮助,将不胜感激,

干杯

只是添加到我的评论,我想我会显示一些基本的代码使用csv模块遍历行,pythons CSV模块文档可以在这里find: https : //docs.python.org/3/library/csv html的

 import csv import xlrd file_location = "C:/Users/Sean/Desktop/DADSA 17-18 COURSEWORK A MALE PLAYERS.csv" if file_location.endswith(".csv"): with open(file_location) as fp: for row in csv.reader(fp): # do something with rows elif file_location.endswith((".xls", ".xlsx")): workbook = xlrd.open_workbook(file_location) # do something with workbook