The pandas style option to add a background gradient is great for quickly inspecting my output table. However, it is applied either row-wise or columns-wise. Would it be pos
You can use axis=None to get rid of the min and max computations in the call:
def background_gradient(s, m=None, M=None, cmap='PuBu', low=0, high=0):
print(s.shape)
if m is None:
m = s.min().min()
if M is None:
M = s.max().max()
rng = M - m
norm = colors.Normalize(m - (rng * low),
M + (rng * high))
normed = s.apply(norm)
cm = plt.cm.get_cmap(cmap)
c = normed.applymap(lambda x: colors.rgb2hex(cm(x)))
ret = c.applymap(lambda x: 'background-color: %s' % x)
return ret
df.style.apply(background_gradient, axis=None)
Edit: You may need to use normed = s.apply(lambda x: norm(x.values)) for this to work on matplotlib 2.2