I have been trying to change the background color of a row based on where the key is present in my lists.
import numpy as npimport pandas as pditem_added = ["UUID1", "UUID22"]item_removed = ["UUID2", "UUID89"]item_changed = ["UUID3", "UUID100"]def highlight_cells_condition(val): if val in item_added: color = "green" elif val in item_removed: color = "red" elif val in item_changed: color = "yellow" else: color = "" return ["background-color: {}".format(color)]arr = np.array( [ ("UUID3", "TYPE1", 0, "AA", "time1", "Items"), ("UUID2", "TYPE2", 0, "BB", "time2", "Items"), ("UUID1", "TYPE1", 1, "CC", "time3", "Vaalves"), ])header = ["UUID", "B", "C", "D", "E", "F"]df = pd.DataFrame(num, columns=header)df.style.applymap(highlight_cells_condition) html = style.to_html()with open("output.html","w+") as fh: fh.write(html)
I can understand that applymap
highlights only the cells for those values are matching in highlight_cells_condition.
Is there a way where I could extend to change the complete row instead of only the cell?
Please see that I am a beginner to pandas and any help will be much appreciated.