Created
October 26, 2020 13:32
-
-
Save mberr/432b27c585c22592dc4df17332660d5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def latex_bold(text: str) -> str: | |
"""Format text in bold font using Latex.""" | |
return rf"\textbf{{{text}}}" | |
def highlight_max( | |
data: pandas.Series, | |
float_formatter: Callable[[float], str] = "{:2.2f}".format, | |
highlighter: Callable[[str], str] = latex_bold, | |
) -> pandas.Series: | |
"""Highlight maximum value in each column.""" | |
is_max = data == data.max() | |
data = data.apply(float_formatter).str.replace("nan", "") | |
data[is_max] = data[is_max].apply(highlighter) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment