Сравните все столбцы по LL
и UL
столбцам и верните стиль данных DataFrame, заполненный numpy.select
:
def highlight(x):
c1 = 'background-color: red'
c2 = 'background-color: green'
c3 = ''
m1 = x.lt(x['LL'], axis=0)
m2 = x.gt(x['UL'], axis=0)
#if necessary set first 2 columns to False
m1.iloc[:, :2] = False
m2.iloc[:, :2] = False
out = np.select([m1, m2], [c1, c2], default=c3)
return pd.DataFrame(out, index=x.index, columns=x.columns)
df.style.apply(highlight, axis=None)
df.style.apply(highlight, axis=None).to_excel('file.xlsx', index=False)
![pic](https://i.stack.imgur.com/v6sJO.png)