【问题标题】:Read from excel using StyleFrame使用 StyleFrame 从 excel 中读取
【发布时间】:2018-08-02 04:16:22
【问题描述】:
sf = sf[[col for col in sf.columns
         if col.style.fill.fgColor.rgb in ('FFFFFFFF', utils.colors.white)]]

读取文件并循环列时出现错误

return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'columns'

我想在不丢失样式值的情况下阅读 excel

【问题讨论】:

  • 问题中的代码和Excel有什么关系?
  • 能否提供import StyleFrame ; print(StyleFrame._versions_)的输出?
  • Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] pandas 0.19.0 openpyxl 2.2.5 StyleFrame 1.3.1跨度>
  • @SureshK 谢谢,终于成功重现。看我的回答。
  • @DeepSpace 非常感谢。我会检查并尽快通知您

标签: python pandas styleframe


【解决方案1】:

这是 StyleFrame 中的一个错误,它是由 [col for col in sf.columns if col.style.fill.fgColor.rgb in ('FFFFFFFF', utils.colors.white)] 返回一个空列表(即,每一列的条件为 False)这一事实引起的。

这将在下一个版本中修复。

临时解决方法:

required_cols = [col for col in sf.columns
                 if col.style.fill.fgColor.rgb in ('FFFFFFFF', utils.colors.white)]
sf = sf[required_cols] if required_cols else StyleFrame(pd.DataFrame(columns=sf.columns))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    相关资源
    最近更新 更多