Unhandled color format: '' " while using xlsxwriter pandas

Question:

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)
Asked By: kriti

||

Answers:

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'
Answered By: Vincent Rupp