How to use `style` in conjunction with the `to_html` classes on a DataFrame?

前端 未结 1 1750
我在风中等你
我在风中等你 2021-01-02 06:17

I have a DataFrame like

df = pd.DataFrame(np.random.randn(10).reshape(2, 5))

df
#              0         1         2         3         4
#    0 -0.067162 -         


        
相关标签:
1条回答
  • 2021-01-02 06:55

    Try this:

    html = df.style.applymap(colorize) \
             .set_table_attributes('border="1" class="dataframe table table-hover table-bordered"') \
             .set_precision(3) \
             .render()
    
    with open('d:/temp/a2.html', 'w') as f:
        f.write(html)
    

    Result:

    0 讨论(0)
提交回复
热议问题