Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display DataFrame() values in bold font in one row only

having dataframe summary being called directly from jupyter cell

summary #(Shift + Enter)

how can I make the highlighted row only (last row) in bold font?

enter image description here

like image 521
Bartek Malysz Avatar asked Dec 04 '22 19:12

Bartek Malysz


1 Answers

Please, please provide the code to at least generate the dataframe you are posting.

For what you want, you can use style.applymap() function. The rest is to find the correct properties of font that can be set to bold and how to set index of last row.

import pandas as pd

def df_style(val):
    return "font-weight: bold"

summary = pd.DataFrame([[0, 0, 0, 0, 0], [1620, 203, 392, 651, 2236]],
                       index=["None", "Total"])

# get a handle on the row that starts with `"Total"`, i.e., the last row here
last_row = pd.IndexSlice[summary.index[summary.index == "Total"], :]
# and apply styling to it via the `subset` arg; first arg is styler function above
summaryStyled = summary.style.applymap(df_style, subset=last_row)

display(summaryStyled)

And below is the output:

enter image description here

like image 130
John Avatar answered Dec 26 '22 19:12

John