Pandas style keyword only works on rows or columns. Is it possible to split it according to sublevels.
For example
np.random.seed(24)
df = pd.DataFrame({'Types': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=['Names','V1','V2','V3'])],
axis=1)
df['Types'][0:7] ="Dang"
df['Types'][7:] ="Fang"
df['Names'][0:3] ="Andy"
df['Names'][3:8] ="Flower"
df['Names'][8:] ="Avril"
df2 = pd.groupby(df,['Types','Names']).mean()
df2
Now I want to highlight the max value according to sublevel
def highlight_max(x):
return ['background-color: yellow' if v == x.max() else ''
for v in x]
df2.style.apply(highlight_max,axis=0,subset=['V1'])
It will highlight in this case max value in column 'V1'. I want basically two max values as per the group levels. So I want to highlighted values. Is there any simple way to do that? None of the intro material covers this basic feature.
