I'm trying to style my table but I'm having a problem because of how my table is made. I want to color individual column which i chose, for every year, but i don't want to involve years in code because i have many tables with different years so it needs to stay this format of table.
I need to apply different gradient colors for 4 columns. This is my code but it won't work. This is a Dropbox link of excel document.
import pandas as pd
import numpy as np
df = pd.read_excel('products2.xlsx', index_col=[0])
df.columns = df.columns.str.split('_', expand=True)
new_data = df.stack(0)
new_data1 = new_data.eval('status = profit - loss + other')
new_data2 = new_data1.eval('index = (profit / status) / (loss / status)')
# if i put here styling my data it will work untill output, which means in the end is not working
#style = new_data2.style.background_gradient(subset=['status'])
output = new_data2.unstack(1).swaplevel(0,1, axis=1).sort_index(axis=1)
style = output.style.background_gradient(subset=['profit', 'loss', 'status', 'index'])
# i need to profit to be green gradient, loss red gradient, status blue and index to be some color
style.to_excel('output_products.xlsx')
Any ideas?