Reputation: 430
Please advise, how can I modify below code to apply to index of p-value
only? Now it is also highlighting the index with Mean of cases with data
which i dont want. Thanks!!
def p_value_bold(val):
bold = 'bold' if (val <= 0.05) & (val > 0) else ''
return 'font-weight: %s' % bold
def negative_yellow(val):
color = 'yellow' if (val <= 0.05) & (val > 0) else ''
return 'background-color:' + color
return return_df.style.applymap(p_value_bold).applymap(negative_yellow)
Upvotes: 0
Views: 315
Reputation: 261880
It would be better if you can provide a test dataset as text.
Nevertheless, can you try:
idx = pd.IndexSlice[return_df.index.get_level_values(level=1)=='p_value', :]
return_df.style.applymap(p_value_bold, subset=idx).applymap(negative_yellow, subset=idx)
Upvotes: 2