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

隐身守侯 提交于 2019-12-10 19:34:32

问题


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?


回答1:


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.

   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:



来源:https://stackoverflow.com/questions/51938245/display-dataframe-values-in-bold-font-in-one-row-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!