我已经编写了这段代码,它说这样的错误可以帮助我解决此问题
我已经安装了xlrd
并再次使用pip install xlrd
import numpy as np
import pandas as pd
import os
datas=pd.read_excel('transactions.xlsx')
datas
并且错误显示如下
XLRDError Traceback (most recent call last)
<ipython-input-61-f7361e459a83> in <module>
2 import pandas as pd
3 import os
----> 4 datas=pd.read_excel('transactions.xlsx')
5 datas
~\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
186 else:
187 kwargs[new_arg_name] = new_arg_value
--> 188 return func(*args, **kwargs)
189 return wrapper
190 return _deprecate_kwarg
~\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
186 else:
187 kwargs[new_arg_name] = new_arg_value
--> 188 return func(*args, **kwargs)
189 return wrapper
190 return _deprecate_kwarg
~\Anaconda3\lib\site-packages\pandas\io\excel.py in read_excel(io, sheet_name, header, names, index_col, parse_cols, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skip_footer, skipfooter, convert_float, mangle_dupe_cols, **kwds)
348
349 if not isinstance(io, ExcelFile):
--> 350 io = ExcelFile(io, engine=engine)
351
352 return io.parse(
~\Anaconda3\lib\site-packages\pandas\io\excel.py in __init__(self, io, engine)
651 self._io = _stringify_path(io)
652
--> 653 self._reader = self._engines[engine](self._io)
654
655 def __fspath__(self):
~\Anaconda3\lib\site-packages\pandas\io\excel.py in __init__(self, filepath_or_buffer)
422 self.book = xlrd.open_workbook(file_contents=data)
423 elif isinstance(filepath_or_buffer, compat.string_types):
--> 424 self.book = xlrd.open_workbook(filepath_or_buffer)
425 else:
426 raise ValueError('Must explicitly set engine if not passing in'
~\Anaconda3\lib\site-packages\xlrd\__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
143 if 'content.xml' in component_names:
144 raise XLRDError('Openoffice.org ODS file; not supported')
--> 145 raise XLRDError('ZIP file contents not a known type of workbook')
146
147 from . import book
XLRDError: ZIP file contents not a known type of workbook
答案 0 :(得分:0)
为面临相同错误的用户提供答案:
import numpy as np
import pandas as pd
import os
datas=pd.read_excel('transactions.xlsx')
datas
这应该起作用,除非Excel文件有问题。尝试使用具有相同扩展名的其他文件。