pandas 写Excel 时报错:ValueError: Writing 0 cols but got 8 aliases
pandas 写Excel 时报错:
Traceback (most recent call last):
File "D:\code_tool\spiderYesmro3\main.py", line 244, in <module>
main()
File "D:\code_tool\spiderYesmro3\main.py", line 33, in main
df.to_excel(writer, sheet_name=cate, header=excel_title, index=False)
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\core\generic.py", line 2374, in to_excel
formatter.write(
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\io\formats\excel.py", line 950, in write
writer._write_cells(
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 492, in _write_cells
for cell in cells:
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\io\formats\excel.py", line 887, in get_formatted_cells
for cell in itertools.chain(self._format_header(), self._format_body()):
File "D:\code_tool\spiderYesmro3\venv\lib\site-packages\pandas\io\formats\excel.py", line 691, in _format_header_regular
raise ValueError(
ValueError: Writing 0 cols but got 8 aliases
复现:
总结:
原因:DataFrame 中的数据源为空导致
本文来自博客园,作者:chuangzhou,转载请注明原文链接:https://www.cnblogs.com/czzz/p/17081370.html