I have a multiindex that I want conditional formatting for the background colour on the different columns based on another sub-column value.
data = {'Product':['Electronic','Electronic','Furniture','Furniture','Electronic','Electronic','Furniture','Furniture','Furniture'],
'Item':['Phone','Computer','Table','Chair','Phone','Computer','Table','Chair','Couch'],
'Region':['Canada','Canada','Canada','Canada','USA','USA','USA','USA','USA'],'In Stock':['Y','N','Y','Y','Y','Y','?','Y','Y'],
'Colour':['Black','Silver','Brown','Black','Black','Black','Black','Black','Black']}
df = pd.DataFrame(data)
df2 = (df.melt(id_vars=['Product','Item','Region'])
.sort_values(['Region', 'variable'], ascending=[True,False])
.pivot(index=['Product','Item'], columns=['Region', 'variable'])
.droplevel(0, axis=1))
Can the columns "Colour" in each Region be coloured based on the value of "In Stock" when exported to excel with xlsxwriter - (Y = Green, ? = Yellow, N = Red)
Is there a way to have a custom sort on the Product (such as the order of Furniture, Supplies, Product)?