Reputation: 35
I have the following dataframe: [1]: https://i.sstatic.net/wBi6V.png
I used the following code to highlight the max values of every cell:
def highlight_max(s):
try:
is_max = s == s.max()
return ['background-color: red' if v else '' for v in is_max]
except TypeError:
pass
except KeyError:
pass
s = df.style.apply(highlight_max, axis=1)
s
But I just want to apply this formatting to a certain row, for example the row 'Book Value Per Share (mrq)'. I can't find any code that helps me with this!!!
Anyone knows?
Upvotes: 2
Views: 655
Reputation: 9577
You can use the subset
argument, passing a tuple (row_indexer, column_indexer)
like so...
s = df.style.apply(highlight_max, axis=1, subset=(0, df.columns))
The row indices are zero-based, so 0
represents the first row, that you want to format.
More details here in the official docs here: Finer control: slicing
Upvotes: 1