Home > Software engineering >  Unhandled color format: '' " while using xlsxwriter pandas
Unhandled color format: '' " while using xlsxwriter pandas

Time:10-31

I am trying to highlight cells when a certain criteria is met but if not, I don't want to add any color. If I try with space, I get the aforementioned error. I can't use white as the cell linings in excel vanish.

Code:

def highlight_cells(val):
    color = 'yellow' if val==5.1 else " "
    return 'background-color: {}'.format(color)


df1 = df1.style.applymap(highlight_cells)

CodePudding user response:

I think the problem is it's expecting a color and you're not giving it a valid color. If you return nothing instead, does this work?

def highlight_cells(val):
  if val == 5.1: return 'background-color: yellow'
  • Related