A | B | C |
---|---|---|
1 | jack has a cat | jack aa |
2 | jim has a car | jack ab |
3 | jack has a dog | jim cc |
4 | jack has a house | jim dd |
I want to high light cell that got Jack with color red, Jim with yellow what I came up with but have no outcome
def highlight_jack(ser):
color= "red" if 'jack' in str(ser) else ''
return f"background-color: {color}"
def highlight_jim(ser):
color= "yellow" if 'jim' in str(ser) else ''
return f"background-color: {color}"
df_merge.style.applymap(highlight_jack, subset=['B'])
df_merge.style.applymap(highlight_jim, subset=['B'])
df_merge.to_excel(writer, sheet_name= sheet, index=False)
writer.save()