leemengtaiwan
11/14/2017 - 11:50 AM

客製化pandas Dataframe 的 style

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))