pandas 仅在一行中以粗体显示 DataFrame() 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51938245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
display DataFrame() values in bold font in one row only
提问by Bartek Malysz
回答by John
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.
对于你想要的,你可以使用 style.applymap() 函数。剩下的就是找到可以设置为粗体的字体的正确属性以及如何设置最后一行的索引。
In [1]:
import pandas as pd
In [2]:
def df_style(val):
return 'font-weight: bold'
In [3]:
summary = pd.DataFrame([[0, 0, 0, 0, 0, ],[1620, 203, 392, 651, 2236]],index=['None','Total'])
summary.style.applymap('font-weight: bold',
subset=pd.IndexSlice[summary.index[summary.index=='Total'], :])
print(summary)
And below is the output:
下面是输出: