【发布时间】:2019-02-10 23:36:32
【问题描述】:
我正在尝试阅读 excel 表 (xlsx),它使用背景颜色来区分值。
我尝试了以下库:
- pandas,没有找到任何选项来读取基于背景颜色的单元格。
-
xlrd.
import xlrd xlrd.open_workbook("filename.xlsx", formatting_info=True)
它给出的错误如下: NotImplementedError:formatting_info=True 尚未实现。
-
StyleFrame(如 DeepSpace 所建议的:Subsetting a dataframe based on cell color and text color in excel sheet )
from StyleFrame import StyleFrame, utils sf = StyleFrame.read_excel('filename.xlsx', read_style=True, use_openpyxl_styles=False)
它给出的错误是:
Traceback (most recent call last):
File "proj_path/read_excel.py", line 22, in <module>
sf = StyleFrame.read_excel('filename.xlsx', read_style=True, use_openpyxl_styles=False)
File "C:\Anaconda\lib\site-packages\StyleFrame\deprecations.py", line 22, in inner
return func(*args, **kwargs)
File "C:\Anaconda\lib\site-packages\StyleFrame\style_frame.py", line 220, in read_excel
_read_style()
File "C:\Anaconda\lib\site-packages\StyleFrame\style_frame.py", line 209, in _read_style
read_comments and current_cell.comment)
File "C:\Anaconda\lib\site-packages\StyleFrame\styler.py", line 127, in from_openpyxl_style
font_color = theme_colors[openpyxl_style.font.color.theme]
TypeError: list indices must be integers or slices, not Integer
非常感谢任何帮助我朝着正确方向前进的建议。
【问题讨论】:
-
您只想导入彩色单元格吗?使用 pandas 导入时遇到什么错误?您可以将其编辑到您的帖子中吗?
-
是的,我没有找到在 Pandas 中读取彩色单元格的任何选项。
-
尝试将文件转换为
filename.xls而不是xlsx用于XLRD -
Subsetting a dataframe based on cell color and text color in excel sheet 的可能重复项具体来说,请参阅我的回答中的第三个示例。
-
感谢@DeepSpace 的建议。它在问题中更新时给出错误。
标签: excel python-3.x pandas xlrd