【发布时间】:2019-01-27 00:37:37
【问题描述】:
【问题讨论】:
标签: pandas ipython jupyter-notebook
【问题讨论】:
标签: pandas ipython jupyter-notebook
请提供代码以至少生成您发布的数据框。
对于你想要的,你可以使用 style.applymap() 函数。剩下的就是找到可以设置为粗体的字体的正确属性以及如何设置最后一行的索引。
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)
下面是输出:
【讨论】:
df_style函数在哪里使用?
style.applymap 的第一个参数。