仅在一行中以粗体显示DataFrame()值 [英] display DataFrame() values in bold font in one row only

查看:264
本文介绍了仅在一行中以粗体显示DataFrame()值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有直接从jupyter单元调用的数据框摘要

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?

推荐答案

请,请提供代码以至少生成您要发布的数据框.

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

对于您想要的内容,可以使用style.applymap()函数.剩下的就是找到可以设置为粗体的正确字体属性,以及如何设置最后一行的索引.

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.

   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)

下面是输出:

这篇关于仅在一行中以粗体显示DataFrame()值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆