我的pandas模块有问题。我尝试使用以下代码在excel文件中读取,这在我同学的计算机上工作,但它在我的计算机上给了我一个错误:
FFT1=pd.read_excel('FFT1.xlsx', sheet_name='sheet1')
名为'FFT1.xlsx'的文件与我的jupyter笔记本在同一个目录中。错误信息显示:
XLRDError Traceback (most recent call last)
~AppDataLocalTemp/ipykernel_7436/2793485739.py in <module>
----> 1 FFT1=pd.read_excel('FFT1.xlsx', sheet_name='sheet1')
D:SoftwaresAnacondalibsite-packagespandasioexcel_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, **kwds)
302
303 if not isinstance(io, ExcelFile):
--> 304 io = ExcelFile(io, engine=engine)
305 elif engine and engine != io.engine:
306 raise ValueError(
D:SoftwaresAnacondalibsite-packagespandasioexcel_base.py in __init__(self, io, engine)
819 self._io = stringify_path(io)
820
--> 821 self._reader = self._engines[engine](self._io)
822
823 def __fspath__(self):
D:SoftwaresAnacondalibsite-packagespandasioexcel_xlrd.py in __init__(self, filepath_or_buffer)
19 err_msg = "Install xlrd >= 1.0.0 for Excel support"
20 import_optional_dependency("xlrd", extra=err_msg)
---> 21 super().__init__(filepath_or_buffer)
22
23 @property
D:SoftwaresAnacondalibsite-packagespandasioexcel_base.py in __init__(self, filepath_or_buffer)
351 self.book = self.load_workbook(filepath_or_buffer)
352 elif isinstance(filepath_or_buffer, str):
--> 353 self.book = self.load_workbook(filepath_or_buffer)
354 elif isinstance(filepath_or_buffer, bytes):
355 self.book = self.load_workbook(BytesIO(filepath_or_buffer))
D:SoftwaresAnacondalibsite-packagespandasioexcel_xlrd.py in load_workbook(self, filepath_or_buffer)
34 return open_workbook(file_contents=data)
35 else:
---> 36 return open_workbook(filepath_or_buffer)
37
38 @property
D:SoftwaresAnacondalibsite-packagesxlrd__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)
168 # files that xlrd can parse don't start with the expected signature.
169 if file_format and file_format != 'xls':
--> 170 raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
171
172 bk = open_workbook_xls(
XLRDError: Excel xlsx file; not supported
我该如何解决这个问题?
- 确保你已经安装了openpyxl,如果你没有尝试
pip install openpyxl
- 将代码更改为
FFT1=pd.read_excel('FFT1.xlsx', sheet_name='sheet1',engine='openpyxl')