I have a mock Data frame which looks something like this.
df = pd.DataFrame({'name':['a','b','c'],
'sex':['M','F','F'],
'percentage': [98,99,99.5]})
What I am trying to do is, if the sex is 'M', I am trying to bold all the elements of the row. And this is how I am trying to do this
def bold_style(val):
if val['sex'] == 'M':
return "font-weight: bold"
df.style.apply(bold_style,axis = 1)
My understanding is that, when I pass axis = 1, the function searches by each row, returning the style wherever the condition is satisfied. But this doesn't seem to be the case. Instead, I get this error.
ValueError: Function <function bold_style at 0x000002369E256820> returned the wrong shape. Result has shape: (3,) Expected shape: (3, 3)
Can anyone help me understand why this is happening?
Thanks