python 客制化pandas Dataframe的风格

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 客制化pandas Dataframe的风格相关的知识,希望对你有一定的参考价值。

from IPython.core.display import display, HTML

styler = (df.style.set_caption('your caption')
            .set_properties(**{'text-align': 'left', 'max-width': '150px'}))
html = styler.render()

# make customized bold font
front_part = re.findall(r'class="data.*?>', html)
html = html.replace('% ','% </b>')
for f in front_parts:
    html = re.sub(f, f + '<b>', html)

# center caption
html = html.replace('<caption>', '<caption style="padding-left: 5.5cm;">')
display(HTML(html))

以上是关于python 客制化pandas Dataframe的风格的主要内容,如果未能解决你的问题,请参考以下文章