小编Map*_*ofu的帖子

Python:Pandas read_excel无法打开.xls文件,不支持xlrd

问题:

我正在使用 pd.read_excel 打开 .xls,但出现错误。

df_cima = pd.read_excel("docs/Presentaciones.xls")

xlrd.biffh.XLRDError: Excel xlsx file; not supported
Run Code Online (Sandbox Code Playgroud)

该文件的后缀是 .xls 但此错误告诉我它是 .xlsx

然后我尝试添加engine="openpyxl",它通常用于当 xlrd 版本不再是 1.2.0 时读取 .xlsx ,然后它给了我另一个错误

openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.
Run Code Online (Sandbox Code Playgroud)

我的环境:

  • 熊猫版本:1.1.5
  • xlrd版本:2.0.1
  • openpyxl版本:3.0.6

我不想将 xlrd 版本更改回 1.2.0,从其他答案中我看到新版本的 xlrd 仅支持 .xls,但我不明白为什么它不适用于我的文件。

提前致谢。

python excel xlrd pandas openpyxl

6
推荐指数
1
解决办法
3万
查看次数

Python:os.listdir OSError [Errno 5] 输入/输出错误:'tmp/json_folder'

问题:

我有一个文件夹(json_folder_large),其中包含 200, 000 多个 json 文件,另一个文件夹(json_folder_small),其中包含 10, 000 个 json 文件。

import os
lst_file = os.listdir("tmp/json_folder_large") # this returns an OSError
OSError: [Errno 5] Input/output error: 'tmp/json_folder_large'
Run Code Online (Sandbox Code Playgroud)

当我将 listdir 与目录路径一起使用时,出现 OSError 我确信路径没有问题,因为我可以对其他文件夹执行相同的操作,而不会出现此 OSError。

lst_file = os.listdir("tmp/json_folder_small") # no error with this
Run Code Online (Sandbox Code Playgroud)

环境:

上面的问题是docker 镜像作为 pycharm 解释器

当解释器是conda env时,没有错误

我能看到的唯一区别是,在我的 docker/preferences/resources/advanced 中,我设置了 4 个 CPU(最大为 6)和 32GB 内存(最大为 64)。

我尝试过:(在docker下)

1.使用Pathlib

import pathlib
pathlib.Path('tmp/json_folder_large').iterdir() # this returns a generator …
Run Code Online (Sandbox Code Playgroud)

python bash operating-system docker oserror

5
推荐指数
1
解决办法
6503
查看次数

标签 统计

python ×2

bash ×1

docker ×1

excel ×1

openpyxl ×1

operating-system ×1

oserror ×1

pandas ×1

xlrd ×1