Traceback (most recent call last): File "C:\Users\admin\AppData\Local\Programs\Python\Python310\2.py", line 12, in <module> df.to_excel(writer,sheet_name=1,index=False) File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py", line 2252, in to_excel formatter.write( File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\formats\excel.py", line 940, in write writer._write_cells( File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\excel\_openpyxl.py", line 477, in _write_cells wks.title = sheet_name File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\openpyxl\workbook\child.py", line 90, in title m = INVALID_TITLE_REGEX.search(value) TypeError: expected string or bytes-like object
时间: 2023-06-28 08:13:18 浏览: 96
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误通常是由于 sheet_name 参数的类型不正确导致的。请确保 sheet_name 参数是字符串类型,而不是整数或其他类型。你可以尝试将 sheet_name 改为字符串类型,例如:
```
df.to_excel(writer, sheet_name='Sheet1', index=False)
```
如果问题仍然存在,请检查你的数据框中是否包含任何非字符串类型的列。如果有,请将它们转换为字符串类型,例如:
```
df['column_name'] = df['column_name'].astype(str)
```
阅读全文