YGA*_*YGA 13 python pandas openpyxl
在 read_excel 之前工作正常之后,今天突然出现了这个错误。无论我使用哪个版本的 python3 - 10 或 11,都会失败。
大家知道解决方法吗?
File "/Users/aizenman/My Drive/code/daily_new_clients/code/run_daily_housekeeping.py", line 38, in <module>
main()
File "/Users/aizenman/My Drive/code/daily_new_clients/code/run_daily_housekeeping.py", line 25, in main
sb = diana.superbills.load_superbills_births(args.site, ath)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aizenman/My Drive/code/daily_new_clients/code/diana/superbills.py", line 148, in load_superbills_births
sb = pd.read_excel(SUPERBILLS_EXCEL, sheet_name="Births", parse_dates=["DOS", "DOB"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/util/_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/util/_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/io/excel/_base.py", line 482, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/io/excel/_base.py", line 1695, in __init__
self._reader = self._engines[engine](self._io, storage_options=storage_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/io/excel/_openpyxl.py", line 557, in __init__
super().__init__(filepath_or_buffer, storage_options=storage_options)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/io/excel/_base.py", line 545, in __init__
self.book = self.load_workbook(self.handles.handle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/io/excel/_openpyxl.py", line 568, in load_workbook
return load_workbook(
^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openpyxl/reader/excel.py", line 346, in load_workbook
reader.read()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openpyxl/reader/excel.py", line 303, in read
self.parser.assign_names()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openpyxl/reader/workbook.py", line 109, in assign_names
sheet.defined_names[name] = defn
^^^^^^^^^^^^^^^^^^^
AttributeError: 'ReadOnlyWorksheet' object has no attribute 'defined_names'
Run Code Online (Sandbox Code Playgroud)
Cj *_*sen 21
我正在使用 Azure Databricks,今天遇到了同样的问题。我查了一下,openpyxl 的版本是 3.1.1。
在我的笔记本的开头,我添加了一行以固定到以前的版本:
%pip install --force-reinstall -v "openpyxl==3.1.0"
Run Code Online (Sandbox Code Playgroud)
之后我的工作又开始了。似乎最近更新中的一些变化导致了这个问题。
目前,我们在python3.8环境(Rocky 8.8 OS)上面临问题。我们将 openpyxl 模块降级到 3.0.9 以解决此问题。
须藤 pip3 安装 openpyxl==3.0.9
好好享受!
| 归档时间: |
|
| 查看次数: |
7453 次 |
| 最近记录: |