Issue
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?
Solution
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
summary.style.applymap(df_style, subset=last_row)
print(summary)
And below is the output:
Answered By - John
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.