PHP前端开发

如何解决 Pandas 读取 XLSX 文件出现的“Excel 文件格式无法确定”错误?

百变鹏仔 2个月前 (01-14) #Python
文章标签 文件格式

pandas 读取所有 xlsx 文件时出现“excel 文件格式无法确定”错误

在使用 pandas 从文件夹中读取所有 xlsx 文件时,可能会遇到如下错误:

excel file format cannot be determined, you must specify an engine manually.

根源

此错误通常是由 ms excel 创建的隐藏临时文件引起的,这些文件会在打开 excel 文件时在同一目录中创建,文件名格式为:

~$datasheet.xlsx

解决方案

为了避免此错误,可以:

注意事项

使用 openpyxl 引擎可能会导致另一个错误:“badzipfile: file is not a zip file”。这是因为 pandas 的旧版本(