How do I colour in cells below 1 as green and cells between 0 and 0.5 yellow for Column C.
Current output:
A B C
0 TT WW -5
1 AA WW 0
2 DD WW 5
Desired:
The following code for me just writes to Excel with no colour change.
import pandas as pd
import numpy as np
df = pd.read_excel("C:\\13\\13\\13.xlsx")
def highlight_vals(val, min=-1111, max=1, color='green'):
if min < val < max:
return 'background-color: %s' % color
else:
return ''
df.style.applymap(highlight_vals, subset=['C'])
def highlight_vals(val, min=0, max=0.5, color='yellow'):
if min < val < max:
return 'background-color: %s' % color
else:
return ''
df.style.applymap(highlight_vals, subset=['C'])
writer = pd.ExcelWriter("C:\\13\\13\\zz.xlsx")
df.to_excel(writer, startrow=0, startcol=0, index = False)
writer.save()
