pythonpandasstyleframe

Read from excel using StyleFrame


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

I got an error when read the file and looping the columns

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

I want to read the excel without loosing the style values


Solution

  • That's a bug in StyleFrame that is caused by the fact that [col for col in sf.columns if col.style.fill.fgColor.rgb in ('FFFFFFFF', utils.colors.white)] returns an empty list (ie, the condition is False for every column).

    This will be fixed in the next version.

    A temporary workaround:

    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))