I have a daily Pivot Table that I export to HTML
The code I use to create it is
HEADER = '''
<html>
<head>
<style>
.df tbody tr:last-child { background-color: #FF0000; }
</style>
</head>
<body>
'''
FOOTER = '''
</body>
</html>
'''
with open("/home/testing_libs/htmlex.html", 'w') as f:
f.write(HEADER)
f.write(pivot1.to_html(classes='pivot1'))
f.write(FOOTER)
The source is a PANDAs dataframe. I would like to create logic with PANDAs to have a column which does NOT appear in the Pivot table, but determines the color of the Pivot cells for Units. In other words, if I compare today's Pivot, or even its precursor Dataframe in terms of 'units', from the previous day, and the current day's 'units' are smaller, then I want that CELL in HTML 'RED' and not black. I don't know whether I can have HTML colored red based on NOT the 'units' values, but the associated positive/negative value comparing the same GROUP's 'units' values. Here is the dataframe that creates the above PIVOT TABLE
widget region industry units
0 oldschool middle tech 10
1 newschool west manufacturing 40
2 upandcomer east manufacturing 50
3 oldschool west manufacturing 40
4 newschool east manufacturing 30
5 upandcomer middle manufacturing 20
6 oldschool middle manufacturing 10
7 newschool east tech 30
8 upandcomer east tech 30
THEN to create PIVOT
pivot1 = pd.pivot_table(frame1,index=['region','widget','industry'])
