Skip to content

Instantly share code, notes, and snippets.

@mberr
Created October 26, 2020 13:32
Show Gist options
  • Save mberr/432b27c585c22592dc4df17332660d5b to your computer and use it in GitHub Desktop.
Save mberr/432b27c585c22592dc4df17332660d5b to your computer and use it in GitHub Desktop.
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