I had posted a question in stackoverflow.com about how I could apply a conditional change to the background color of the column in absolute value. https://stackoverflow.com/questions/56202218/pandas-styling-conditional-change-background-color-of-column-by-absolute-valu. But, I have not received an answer yet. Later, my friend helped me write a small code to replicate the case. He was inspired by this message in stackoverflow.com https://stackoverflow.com/questions/38931566/pandas-style-background-gradient-both-rows-and-columns.
But, for whatever reason, this code does not work. But, I can not understand where is a problem.
import pandas as pd import matplotlib.pyplot as a plt of matplotlib import colors df = pd.DataFrame ([[3,2,10,4],[20,1,3,2],[5,4,6,1]]) def background_gradient (s, m = None, M = None, cmap = "PuBu", low = 0, high = 0): s = s.applymap (lambda x: abs (x-6)) if m is None: m = s.min (). min () if M is None: M = s.max (). Max () rng = M-m norm = color.Normalize (m- (rng * low), M + (rng * high)) normed = s.apply (standard) 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 back df.style.apply (background_gradient, axis = None)