- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过 pandas 将 excel 文件(.xls)读入数据框,如下所示:
df = pd.read_excel(
filename, sheet_name='Sheet1', nrows=6)
不幸的是,我得到了一个 AssertionError。但是,如果我在 excel 中打开文件然后单击保存,然后重新运行它就可以了。我没有更改任何数据,只是在 Excel 中打开并保存。有没有人遇到过这个问题?
AssertionError Traceback (most recent call last)
<ipython-input-153-58dcba1b45c3> in <module>
1 df = pd.read_excel(
----> 2 filename, sheet_name='Sheet1', nrows=6)
~\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
206 else:
207 kwargs[new_arg_name] = new_arg_value
--> 208 return func(*args, **kwargs)
209
210 return wrapper
~\Anaconda3\lib\site-packages\pandas\io\excel\_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, skip_footer, skipfooter, convert_float, mangle_dupe_cols, **kwds)
308
309 if not isinstance(io, ExcelFile):
--> 310 io = ExcelFile(io, engine=engine)
311 elif engine and engine != io.engine:
312 raise ValueError(
~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py in __init__(self, io, engine)
817 self._io = _stringify_path(io)
818
--> 819 self._reader = self._engines[engine](self._io)
820
821 def __fspath__(self):
~\Anaconda3\lib\site-packages\pandas\io\excel\_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
~\Anaconda3\lib\site-packages\pandas\io\excel\_base.py in __init__(self, filepath_or_buffer)
357 self.book = self.load_workbook(filepath_or_buffer)
358 elif isinstance(filepath_or_buffer, str):
--> 359 self.book = self.load_workbook(filepath_or_buffer)
360 else:
361 raise ValueError(
~\Anaconda3\lib\site-packages\pandas\io\excel\_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
~\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)
155 formatting_info=formatting_info,
156 on_demand=on_demand,
--> 157 ragged_rows=ragged_rows,
158 )
159 return bk
~\Anaconda3\lib\site-packages\xlrd\book.py in open_workbook_xls(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
118 bk._sheet_list = [None for sh in bk._sheet_names]
119 if not on_demand:
--> 120 bk.get_sheets()
121 bk.nsheets = len(bk._sheet_list)
122 if biff_version == 45 and bk.nsheets > 1:
~\Anaconda3\lib\site-packages\xlrd\book.py in get_sheets(self)
721 for sheetno in xrange(len(self._sheet_names)):
722 if DEBUG: print("GET_SHEETS: sheetno =", sheetno, self._sheet_names, self._sh_abs_posn, file=self.logfile)
--> 723 self.get_sheet(sheetno)
724
725 def fake_globals_get_sheet(self): # for BIFF 4.0 and earlier
~\Anaconda3\lib\site-packages\xlrd\book.py in get_sheet(self, sh_number, update_pos)
712 sh_number,
713 )
--> 714 sh.read(self)
715 self._sheet_list[sh_number] = sh
716 return sh
~\Anaconda3\lib\site-packages\xlrd\sheet.py in read(self, bk)
1107 saved_obj_id = None
1108 elif rc == XL_NOTE:
-> 1109 self.handle_note(data, txos)
1110 elif rc == XL_FEAT11:
1111 self.handle_feat11(data)
~\Anaconda3\lib\site-packages\xlrd\sheet.py in handle_note(self, data, txos)
1985 # string length).
1986 # Issue 4 on github: Google Spreadsheet doesn't write the undefined byte.
-> 1987 assert (data_len - endpos) in (0, 1)
1988 if OBJ_MSO_DEBUG:
1989 o.dump(self.logfile, header="=== Note ===", footer= " ")
AssertionError:
最佳答案
如果您的数据中有一个尚未设置为“日期”格式的日期列,则通常会发生这种情况。在excel中将日期列设置为“日期”,错误将消失。
关于python - 使用 xlrd 引擎在 xls 文件上调用 pands read_excel 时出现 AssertionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63832892/
这个问题在这里已经有了答案: Specifying Column Types when Importing xlsx Data to R with Package readxl (6 个回答) 2年前
我正在使用 readxl 包来加载 Excel 文件。默认情况下,它应该去除空白,但它没有这样做。 该文件可以直接从下面的链接下载,也可以通过附录B所在的网站下载 http://www2.nation
我的 .xlsx Excel 工作表中的列名称包含空格。如何自动将空格替换为“_”或“.”?我想使用 read_excel 因为我需要在 Excel 工作表中指定一个范围。 最佳答案 这是一种使用 .
我有一个 .xlsx 文件有两个工作表,我想使用 readxl 包中的 read_excel 生成两个 Excel 工作表的列表。我用过这段代码 my_work <- lapply(excel_she
我的 .xlsx Excel 工作表中的列名称包含空格。如何自动将空格替换为“_”或“.”?我想使用 read_excel 因为我需要在 Excel 工作表中指定一个范围。 最佳答案 这是一种使用 .
我喜欢使用 readxl包裹。但是,我一直将它用作 RMarkdown 文档和一些 read_excel() 文档的一部分。读入文件时的消息在进行分析时很有用,但在尝试呈现分析时则不然。所以问题是,在
我正在尝试读取包含多个工作表的 Excel 文件,如下所示: sumtech = pd.read_excel('excelfile.xlsx', sheet_name=None) 其中一张工作表具有以
我花了几个小时努力如何使用 pd.read_excel 读取 excel 文件,其中路径是网站地址。我发现链接不会直接转到文件,而只是触发下载。有什么简单的方法可以解决吗? 部分代码: link_en
你好,这是我第一次发帖, 我正在尝试从在线网页链接 excel 表中获取数据。但是,它适用于页面上的其他链接,但不适用于返回空白数据框的特定链接。 library(readxl) download.f
我有一张我想读入 Pandas 多索引数据框的 excel 表。复杂之处在于 excel 表包含重复的标题值。阅读 pandas 时,将 .x 添加到第二级标题的末尾而不是第一级。有没有办法必须重命名
我使用 read_excel 的读取时间真的很慢在具有特定 xlsm 文件的特定机器上。在 2 台不同的机器上读取相同的 xlsm 文件,我的读取时间为 72 秒与 0.2 秒。较慢的机器实际上具有更
我没有找到这个问题的答案,所以希望这是在这方面获得帮助的地方。 我正在阅读包含在 .zip 文件中的许多 Excel 文件。我拥有的每个 .zip 文件都有大约 40 个我想阅读的 excel 文件。
使用以下代码从 Excel 中读取表格,丢弃列标题下的空行,并重命名索引: Energy = pd.read_excel('assets/Energy Indicators.xls', header=
我使用 readxl 包中的 read_excel 读取一个文件,其中我想将其中的 3 列强制转换为文本,其余的我很乐意让 read_excel 猜类型。我可以这样做吗? 我尝试使用 col_type
我有一个冗长的 python 代码与使用 pandas 的 excel 接口(interface)。我的代码打开文件,运行一些 VBA 来更新工作表中的表,保存文件,然后将该表读取到 python 中
想知道是否有任何方法或技术可以忽略excel工作簿(read_excel)中隐藏的excel_sheet。 为什么我要问的是,在许多工作表中隐藏了许多 Excel 文件。 到目前为止我已经尝试过的链接
我正在尝试将相当困惑的 Excel 文件读取到 Polars 数据帧,但收到“XlsxValueError:错误:潜在无效的日期格式。”。 我认为该问题与某些采用 Excel 数字日期格式的日期列值有
我正在将一个 excel 文件导入 R。我只想保留 A 和 C 列而不是 B(列按顺序为 A、B、C),但以下代码也保留 B 列。如何在不在另一行代码中进行子集化的情况下摆脱 B 列? df <- r
是否可以使用 pandas 从 Excel 工作表文件中读取多个表?就像是:读取 table1 从 row0 到 row100读取 table2 从第 102 行到第 202 行... 最佳答案 我编
我有一个 Excel 电子表格,正在将其读入 Pandas DataFrame: df = pd.read_excel("file.xls") 但是,电子表格的其中一列包含具有与其关联的超链接的文本。
我是一名优秀的程序员,十分优秀!