pandas 属性错误:“ReadOnlyWorksheet”对象没有属性“defined_names

gev0vcfq  于 2023-03-11  发布在  其他
关注(0)|答案(2)|浏览(1224)

我试图打开一个xlsx文件与Pandas和我收到这个错误:

Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[20], line 1
----> 1 df = pd.read_excel("C:/Users/*****/OneDrive - *******/Bureau/file_name.xlsx", sheet_name="")

File c:\Users\*******\OneDrive - ********\Bureau\file_name\venv\lib\site-packages\pandas\util\_decorators.py:211, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
    209     else:
    210         kwargs[new_arg_name] = new_arg_value
--> 211 return func(*args, **kwargs)

File c:\Users\******\OneDrive - *******\Bureau\file_name\venv\lib\site-packages\pandas\util\_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    325 if len(args) > num_allow_args:
    326     warnings.warn(
    327         msg.format(arguments=_format_argument_list(allow_args)),
    328         FutureWarning,
    329         stacklevel=find_stack_level(),
    330     )
--> 331 return func(*args, **kwargs)

File c:\Users\******\OneDrive - ******\Bureau\file_name\venv\lib\site-packages\pandas\io\excel\_base.py:482, 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, na_filter, verbose, parse_dates, date_parser, thousands, decimal, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options)
    480 if not isinstance(io, ExcelFile):
    481     should_close = True
--> 482     io = ExcelFile(io, storage_options=storage_options, engine=engine)
    483 elif engine and engine != io.engine:
    484     raise ValueError(
...
--> 109     sheet.defined_names[name] = defn
    111 elif reserved == "Print_Titles":
    112     titles = PrintTitles.from_string(defn.value)

AttributeError: 'ReadOnlyWorksheet' object has no attribute 'defined_names'
"

我使用的是python 3.10版本,也尝试了3.11.2版本,Pandas的版本是1.5.3,我也尝试了这个主题中的解决方案;
'ReadOnlyWorksheet' object has no attribute 'defined_names'
我降级了openpyxl并再次升级,尝试了几次,但没有。仍然得到同样的错误。我尝试了不同的文件xlsm,工作正常,但不是与xlsx。
所以我的atm卡死了!

zazmityj

zazmityj1#

here所述,需要降级到3.1.0:

pip install --force-reinstall -v "openpyxl==3.1.0"
djmepvbi

djmepvbi2#

重启内核。
有同样的问题,将openpyxl版本降级到3.1.0,仍然不工作。
重新启动并再次运行。
成功了!

相关问题